facet_grid() forms a matrix of panels defined by row and column faceting variables. It is most useful when you have two discrete variables, and all combinations of the variables exist in the data.
facet_wrap() makes a long ribbon of panels (generated by any number of variables) and wraps it into 2d. This is useful if you have a single variable with many levels and want to arrange the plots in a more space efficient manner. You can control how the ribbon is wrapped into a grid with ncol , nrow , as.
Facet plots, also known as trellis plots or small multiples, are figures made up of multiple subplots which have the same set of axes, where each subplot shows a subset of the data.
Use the theme function:
library(grid)
p + theme(panel.spacing = unit(2, "lines"))
See also here: Slicing plots generated by ggplot2
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"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With