如何仅在 ggplot 中隐藏 geom_label 的图例?
How to hide legend for geom_label only in ggplot?
我有一个 ggplot 对象来按星期几绘制结果:
ggplot(weekdays, aes(x=weekday, fill=weekday, y=outcome_mean, ymin=outcome_lci, ymax=outcome_uci)) +
geom_col() +
geom_errorbar() +
theme_bw() +
geom_label(aes(label=paste(visits, "Visits", sep=" ")), y=-0.75, size=3.5, color="black", fontface="bold") +
labs(y="Outcome Mean", x="Weekday", title = "Outcome by Weekday", fill="Weekday:") +
theme(panel.grid.minor = element_line(colour="lightgrey", size=0.5)) +
theme(panel.grid.major = element_line(colour="lightgrey", size=0.5)) +
theme(axis.text.x = element_text(face="bold", size=10)) +
theme(axis.text.y = element_text(face="bold", size=12)) +
theme(axis.title.x = element_text(face="bold", size=16)) +
theme(axis.title.y = element_text(face="bold", size=16)) +
theme(legend.text= element_text(face="bold", size=12)) +
theme(legend.title= element_text(face="bold", size=14)) +
theme(plot.title= element_text(face="bold", size=16, hjust=0.5)) +
#scale_label(guide=FALSE) +
scale_y_continuous(limits=c(-1,20), breaks= seq(0,30,2), minor_breaks=seq(0,30,1))
给出:
但是我不喜欢填充图例中的小 "a" 符号,我如何在不隐藏整个图例的情况下去掉这些符号(因为在我的一些图中 x 和 fill 是不同的变量所以我需要保留填充图例)?
我试过添加 "scale_label(guide=FALSE)"(上面已注释掉),但这不是公认的功能。
有谁知道我怎样才能做到这一点?
...
geom_label(..., show.legend = FALSE) +
...
我有一个 ggplot 对象来按星期几绘制结果:
ggplot(weekdays, aes(x=weekday, fill=weekday, y=outcome_mean, ymin=outcome_lci, ymax=outcome_uci)) +
geom_col() +
geom_errorbar() +
theme_bw() +
geom_label(aes(label=paste(visits, "Visits", sep=" ")), y=-0.75, size=3.5, color="black", fontface="bold") +
labs(y="Outcome Mean", x="Weekday", title = "Outcome by Weekday", fill="Weekday:") +
theme(panel.grid.minor = element_line(colour="lightgrey", size=0.5)) +
theme(panel.grid.major = element_line(colour="lightgrey", size=0.5)) +
theme(axis.text.x = element_text(face="bold", size=10)) +
theme(axis.text.y = element_text(face="bold", size=12)) +
theme(axis.title.x = element_text(face="bold", size=16)) +
theme(axis.title.y = element_text(face="bold", size=16)) +
theme(legend.text= element_text(face="bold", size=12)) +
theme(legend.title= element_text(face="bold", size=14)) +
theme(plot.title= element_text(face="bold", size=16, hjust=0.5)) +
#scale_label(guide=FALSE) +
scale_y_continuous(limits=c(-1,20), breaks= seq(0,30,2), minor_breaks=seq(0,30,1))
给出:
但是我不喜欢填充图例中的小 "a" 符号,我如何在不隐藏整个图例的情况下去掉这些符号(因为在我的一些图中 x 和 fill 是不同的变量所以我需要保留填充图例)?
我试过添加 "scale_label(guide=FALSE)"(上面已注释掉),但这不是公认的功能。
有谁知道我怎样才能做到这一点?
...
geom_label(..., show.legend = FALSE) +
...