ggplot:如何增加刻面图之间的间距?

时间:2010-09-10 01:03:35

标签: r ggplot2

我有几个多面的直方图(通过下面的命令获得),它们很好地一个接一个地绘制。我想增加它们之间的间距,但是它们很紧。

我查看了doc,但未找到此参数。

提前致谢。

qplot (Happiness.Level, Number.of.Answers, data=mydata, geom="histogram") + facet_grid (Location ~ .) 

2 个答案:

答案 0 :(得分:131)

使用theme功能:

library(grid)

p + theme(panel.spacing = unit(2, "lines"))

另见:Slicing plots generated by ggplot2

答案 1 :(得分:6)

只是添加到@rcs 响应中:

# Change spacing between facets on both axis
p + theme(panel.spacing = unit(2, "lines"))

# Change horizontal spacing between facets
p + theme(panel.spacing.x = unit(2, "lines"))

# Change vertical spacing between facets
p + theme(panel.spacing.y = unit(2, "lines"))