130
votes

I have several faceted histograms (obtained with the command below) which are nicely plotted one under the other. I would like to increase the spacing between them, however, they are tight.

I looked at the doc but didn't find a parameter for this.

qplot (Happiness.Level, Number.of.Answers, data=mydata, geom="histogram") + facet_grid (Location ~ .) 
2
A side comment that I found another way to approach this (used a faced_wrap instead of facet_grid and the resulting chart is better looking). I'm still interested if there is a way to address the original question.wishihadabettername
Try theme_get() for a slew of hidden options that you can adjust with opts()Brandon Bertelsen

2 Answers

201
votes

Use the theme function:

library(grid)

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

See also here: Slicing plots generated by ggplot2

6
votes

Just to add to @rcs response:

# 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"))