Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R ggplot2中的图例,删除标高_R_Ggplot2_Legend - Fatal编程技术网

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")