R ggplot2中的图例,删除标高
我的数据:R ggplot2中的图例,删除标高,r,ggplot2,legend,R,Ggplot2,Legend,我的数据: df <- data.frame(sp = c(LETTERS[1:8]), tr = c("NS", "LS", "NS", "LS", "LS", "HS", "HS", "HS"), bv = c(14, 5, 11, 5.6, 21, 5.4, 2, 4.8), av = c(0.0, 14, 21, 48.4, 15, 55.6, 37, 66.2)) df您可以通
df <- data.frame(sp = c(LETTERS[1:8]),
tr = c("NS", "LS", "NS", "LS", "LS", "HS", "HS", "HS"),
bv = c(14, 5, 11, 5.6, 21, 5.4, 2, 4.8),
av = c(0.0, 14, 21, 48.4, 15, 55.6, 37, 66.2))
df您可以通过在guides
中设置fill=FALSE
来删除变量
图例,并在guides\u图例
中使用覆盖.aes
更改背景色,如下所示:
ggplot(df1, aes(sp, value, fill = variable)) +
geom_bar(aes(lty = tr), lwd = 1.2, stat = "identity", colour = "black", width =.8) +
scale_linetype_discrete(name = "ja") +
guides(fill = FALSE,
lty = guide_legend(override.aes = list(lty = c('dotted', 'dashed', 'solid'),
fill = "white"))) +
theme_classic() +
theme(legend.position = "bottom")
这将导致以下绘图:
ggplot(df1, aes(sp, value, fill = variable)) +
geom_bar(aes(lty = tr), lwd = 1.2, stat = "identity", colour = "black", width =.8) +
scale_linetype_discrete(name = "ja") +
guides(fill = FALSE,
lty = guide_legend(override.aes = list(lty = c('dotted', 'dashed', 'solid'),
fill = "white"))) +
theme_classic() +
theme(legend.position = "bottom")