【问题标题】:Outline the entire bar of geom_bar勾勒geom_bar的整个bar
【发布时间】:2020-01-20 05:26:42
【问题描述】:

如何在整个条形周围形成黑色轮廓,而不是像下面的示例图中那样出现多个黑色轮廓:

`diamonds %>% 
select(carat, cut) %>% 
distinct() %>% 
ggplot() +
geom_bar(aes(x=factor(cut), y=factor(carat), fill=factor(carat)), 
     stat = "identity", colour="black") +
theme(legend.position = "none")`

我希望“color=black”围绕每个条形。

谢谢

【问题讨论】:

    标签: r ggplot2 colors geom-bar


    【解决方案1】:

    从技术上讲,每个条形周围都有黑色边框。但是,对于每个cut,您都有很多条,每个值对应carat。如果你想要的是每堆条周围的黑色边框,那么我建议首先绘制有边框,然后绘制没有边框:

    diamonds %>% 
      select(carat, cut) %>% 
      distinct() %>% 
      ggplot() +
      geom_bar(aes(x=factor(cut), y=factor(carat)), 
               stat = "identity", color = "black", size = 1) +
      geom_bar(aes(x=factor(cut), y=factor(carat), fill=factor(carat)), 
               stat = "identity") +
      theme(legend.position = "none")
    

    提供:

    【讨论】:

      猜你喜欢
      • 2011-12-17
      • 2014-08-23
      • 1970-01-01
      • 1970-01-01
      • 2015-11-11
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多