【发布时间】:2021-08-20 11:53:51
【问题描述】:
我正在尝试根据以下df生成一个ggplot
df <- data.frame(
Input = c("S1", "S2", "S3", "S4"),
Brand = c("Brand01", "Brand01", "Brand01", "Brand01", "Brand02","Brand02","Brand02","Brand02"),
Average = c(21.52027, 21.60699, 20.77871, 21.22759, 25.05574, 22.74372, 22.80795, 22.98509),
Limit = c(31.89098, 31.89098, 31.89098, 31.89098, 31.57953, 31.57953, 31.57953, 31.57953))
p = ggplot(df, aes(x=Input, y=Average, fill=Brand)) +
facet_wrap(~ Brand, ncol = 2) +
geom_bar(stat="identity", position=position_dodge(), colour="black", width = 0.9, show.legend = FALSE) +
xlab("Input") + ylab("Average") +
theme(axis.title.x = element_text(size=14), axis.title.y = element_text(size=14),
legend.text = element_text(size=14), plot.title = element_text(size = 20, face = "bold"),
axis.text.x = element_text(size=6))+
theme(axis.text.x = element_text(angle = 90)) +
geom_hline(aes(yintercept=Limit, linetype = "dashed"), color = "red") +
scale_linetype_manual(name = "Limit", values = "dashed", labels = "")
当show.legend = FALSE 时,情节看起来像
但是当我有show.legend = TRUE
然后限制框改变颜色,我想让它像第一个情节一样“灰色”或白色。 我尝试了其他相关主题的一些技巧,但没有任何效果。
【问题讨论】: