翻转坐标后,如何减少窄条和面板边框之间的空间?使用数据框 df 和 ggplot
命令,底部栏和刻度线之间有很多空白空间(同样在“供应商”栏上方有一个宽阔的空间)。
df <- data.frame(x = c("firm", "vendor"), y = c(50, 20))
ggplot(df, aes(x = x, y = y)) +
geom_bar(stat = "identity", width = 0.4) +
theme_tufte() + coord_flip() +
labs(x = "", y = "")
我试过
scale_x_discrete
与两者 limits
和 expand
论据无济于事以及position = position dodge
,同样没有效果。此 question提供
coord_equal
更改纵横比,从而减少或消除额外空间,但请注意该解决方案不适用于 coord_flip
.
最佳答案
我想我已经找到了解决办法。您可以删除 width
来自 geom_bar
并介绍theme(aspect.ratio = .2)
,然后您可以使用比例来找到所需的宽度。而不像coord_equal
或 coord_fixed
兼容 coord_flip
.
ggplot(df, aes(x = x, y = y)) +
geom_bar(stat = "identity") +
theme_tufte() + theme(aspect.ratio = .2) +
coord_flip() +
labs(x = "", y = "")
关于r - ggplot2:如何在 coord_flip 和面板边框之后减少窄条之间的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31905926/