如何调整R中水平条之间的差距?

How to adjust the gap between horizontal bars in R?

如何减小图表中水平放置的条柱之间的距离?这样我就可以在有页数限制的文章中节省space了。作为示例,我准备了以下代码和截图。

library(ggplot2)
survey <- data.frame(fruit=c("Apple", "Banana", "Grapes", "Kiwi", "Orange", "Pears"),
                     people=c(40, 50, 30, 15, 35, 20),tur=c("A","B","A","B","B","A"))
ggplot(survey, aes(x=fruit, y=people)) +
    geom_col(show.legend = FALSE,width = 0.5)+
  facet_wrap(~tur, ncol = 2,scales = "free")+
    coord_flip()

也许aspect.ratio可以帮忙?

我怀疑问题可能是由于设备的绘图区域而不是 ggplot,它似乎填满了设备区域。

使用 facet_wrap 修改后的数据,您将返回使用 aspect.ratio

ggplot(survey1, aes(x = fruit, y = people)) +
  geom_col(show.legend = FALSE, width = 0.9)+
  facet_wrap(~tur, ncol = 2, scales = "free")+
  coord_flip()+
  theme(aspect.ratio = 0.3)

也许问题是理解你如何将情节转移到你的文章中。

ggsave("skinny_plot.png", width = 150, height = 40, units = "mm")

ggsave("skinny_plot.pdf", width = 150, height = 40, units = "mm")

这给你:

数据

survey1 <- data.frame(fruit=c("Apple", "Banana", "Grapes", "Kiwi", "Orange", "Pears"),
                     people=c(40, 50, 30, 15, 35, 20),
                     tur=c("A","B","A","B","B","A"))

reprex package (v2.0.0)

于 2021-04-16 创建