【问题标题】:Legends of two ggplot in grid.arrange() are overlapping in R Markdowngrid.arrange() 中两个 ggplot 的图例在 R Markdown 中重叠
【发布时间】:2019-06-12 07:12:12
【问题描述】:

grid.arrange() 中两个 ggplot 图中的图例重叠。我使用了 legend.positon = "top" 或 "bottom",出现了另一个问题,即 ggplot 没有显示完整的图例。其实我的传说还蛮长的。如何让图例打印成两行以避免上述问题?

我尝试过 legend.position = "top",还有 legend.box = "vertical" 但没有任何效果

k1 %>% 
  ggplot(aes(Alert,Sum, fill = Alert)) + 
  geom_bar(stat = "identity") + 
  facet_wrap(~ Model , nrow= 5) + 
  coord_flip() + 
  geom_text(aes(label = Sum), fontface = "bold") + 
  theme(legend.position = "none")+ 
  ggtitle("MODEL WISE ALERT COUNT")+ 
  theme_grey(base_size = 22)+
  theme(legend.position = "top")

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    我找到了答案。

    k1 %>% ggplot(aes(Alert,Sum, fill = Alert)) + geom_bar(stat = "identity") + facet_wrap(~ Model , nrow= 5) + coord_flip() + geom_text(aes(label = Sum), fontface = "bold") + ggtitle("MODEL WISE ALERT COUNT")+ theme_grey(base_size = 22)+theme(legend.position = "bottom") **+ guides(fill=guide_legend(nrow=2, byrow=TRUE))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多