概述 geom_bar 的整个栏

Outline the entire bar of geom_bar

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

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

我希望 "colour=black" 包围每个小节。

谢谢

从技术上讲,每个栏周围都有黑色边框。但是,对于每个 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")

给出: