Facets

library(ggh4x)
#> Loading required package: ggplot2

The ggh4x package has some extended options for tweaking the appearance of facets.

Extended facets

This package offers two extensions to the vanilla facet_wrap() and facet_grid() that give you more control of the placement of axes at the inner facets.

Wrap

The default behaviour of facet_wrap2() is to replicate exactly what ggplot2::facet_wrap() does.

# Make a standard plot
p <- ggplot(mpg, aes(displ, hwy, colour = as.factor(cyl))) + geom_point() +
  labs(x = "Engine displacement", y = "Highway miles per gallon") +
  guides(colour = "none")

p + facet_wrap2(vars(class))

The difference is even when scales = "fixed" (the default), you can draw the axes at (some or all) inner facets with the axes argument. Moreover, you can choose to omit the axis labels but keep the axis ticks of the inner facets by setting the remove_labels argument.

p + facet_wrap2(vars(class), axes = "all", remove_labels = "x")