Ggplot2: how to reduce space between narrow width bars, after cop_flip and panel border
When you flip the coordinates, how do you reduce the space between the narrow nodes and the border of the panel? Using df data commands and commands ggplot
, there are many gaps between the bottom pane and the labels (and similarly the wide space above the "provider" pane).
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 = "")
I've tried scale_x_discrete
with arguments limits
and to expand
no avail, and also with position = position dodge
, also with no effect.
This question suggests coord_equal
changing the aspect ratio and thereby reducing or eliminating the extra space, but notes that the solution doesn't work with coord_flip
.
source to share
I think I have found a solution. You can remove width
from geom_bar
and enter theme(aspect.ratio = .2)
, then you can play with the odds to find the width you want. And unlike coord_equal
or is coord_fixed
compatible with coord_flip
.
ggplot(df, aes(x = x, y = y)) +
geom_bar(stat = "identity") +
theme_tufte() + theme(aspect.ratio = .2) +
coord_flip() +
labs(x = "", y = "")
source to share