[英]Removing the bottom border for borders in geom_bar
我正在寻找一种在geom_bar
添加时删除非重叠底部边框的方法。 我不想使用像geom_hline(yintercept = 0, colour = "white")
这样的选项,因为它听起来很挑剔,因为它覆盖了原始条的单行像素。 我猜我可能不得不直接修改 ggproto object 的内部,但我不知道如何 go 这样做。
示例代码:
plot <- iris %>% ggplot(aes(Species, Sepal.Length, fill = Species)) +
geom_bar(stat = "summary", fun.y = "mean", colour = "black")
所需的 output:
您可以禁用黑色边框
geom_bar(..., colour = "NA")
然后需要重新绘制它们。 根据需要调整width
和+/- 0.5
以适当地间隔条。
library(dplyr)
library(ggplot2)
x <- iris %>%
group_by(Species) %>%
summarise(m=mean(Sepal.Length)) %>%
mutate(Species.x = as.integer(as.factor(Species))) %>% ungroup
y <- bind_rows(
x %>%
mutate(
Species.x = Species.x - 0.5,
y = 0
),
x %>%
mutate(
Species.x = Species.x - 0.5,
y = m
),
x %>%
mutate(
Species.x = Species.x + 0.5,
y = m
),
x %>%
mutate(
Species.x = Species.x + 0.5,
y = 0
)
)
ggplot(x, aes(Species.x, m)) +
geom_col(aes( fill=Species), colour=NA, width=1) +
geom_path(data=y, aes(y=y, group=Species), color='black') +
scale_x_continuous(breaks=x$Species.x, labels=x$Species)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.