align_plots()
Plot Composer - Inset
library(grid)
# Create the main scatter plot: mpg vs disp
p1 <- ggplot(mtcars) +
geom_point(aes(mpg, disp))
# Create the inset plot: boxplot of disp by gear
p2 <- ggplot(mtcars) +
geom_boxplot(aes(gear, disp, group = gear))
# Compose the plots: insert p2 into p1 using a viewport
p1 + inset(p2, vp = viewport(0.6, 0.6,
just = c(0, 0), width = 0.4, height = 0.4
))