当您翻转坐标时,如何减少窄条和面板边框之间的空间?使用数据框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 = "")
Run Code Online (Sandbox Code Playgroud)
我尝试scale_x_discrete
了两者limits
和expand
参数都无济于事position = position dodge
,同样没有效果.
这个问题提供coord_equal
了改变宽高比,从而减少或消除额外空间,但注意到该解决方案不起作用coord_flip
.
mpa*_*nco 10
我想我找到了解决方案.您可以删除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 = "")
Run Code Online (Sandbox Code Playgroud)