自從ggplot2 3.3.5版本更新后,將斷點設定為任意數字以限制圖例中顯示的鍵的數量不再起作用,而是將缺失的斷點設定為新的NA=灰色默認值:
df_Test < - tibble(Year = rep(c("2019"/span>。 "2020", "2021")。 每個= 3),
尺寸 = c(20。 30, 25, 24。 20, 30, 35。 24, 20),
Color_Index = fct_relevel(as. factor(1 : 9))
)
Color_Scale < - c("#dce6f2", "#4f81bd"。 "#254061", "#4f81bd", "#254061"/span>。 "#dce6f2", "#254061"。 "#dce6f2", "#4f81bd")
ggplot(data = df_Test。 映射= aes(x = Annual, y = size, fill = Color_Index。 order = Color_Index)
geom_bar(stat = "identity")
geom_text(mapping = aes(label = size, 組= Color_Index),
position = position_stack(vjust = 0。 5), size = 6。 統計= "identity")
scale_fill_manual(values = Color_Scale,
休息= c("1"。 "2","3"),
標簽 = c(""。 "","")
guides(fill = guide_legend(title = "Cohorts"))
有誰知道我怎樣才能限制新版本中顯示的圖例鍵的數量?
預先感謝!
uj5u.com熱心網友回復:
你必須命名這些值。但我不確定這是否是你想要的:
ggplot(data = df_Test。 映射= aes(x = Annual, y = size, fill = Color_Index。 order = Color_Index)
geom_bar(stat = "identity")
geom_text(mapping = aes(label = size, 組= Color_Index),
position = position_stack(vjust = 0。 5), size = 6。 統計= "identity")
scale_fill_manual()
values = setNames(Color_Scale[1: 3], 作為。 character(1: 3)),
突破 = c("1"/span>。 "2","3"),
標簽 = c(""。 "",""),
na.value = "yellow")
guides(fill = guide_legend(title = "Cohorts"))
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/318895.html
標籤:

