

The labels argument puts separate labels on each panel for captioning. To make a single row of plots I use nrow = 1. The function plot_grid() in cowplot is for combining plots. Scale_x_continuous(breaks = seq(0, 35, by = 5) ) Slpplot = ggplot(dat, aes(x = slp, y = resp) ) + Scale_x_continuous(breaks = seq(0, 1, by = 0.2) ) Gradplot = ggplot(dat, aes(x = grad, y = resp) ) + elevplot = ggplot(dat, aes(x = elev, y = resp) ) + Today I’m going to make the three plots manually. If doing lots of these we’d want to use some sort of loop to make a list of plots as I’ve demonstrated previously. The first step is to make each of the three plots separately. Package cowplot is a really nice package for combining plots, and has lots of bells and whistles along with some pretty thorough vignettes. In that case, it may make more sense to create separate plots and then combine them into a small multiples plot with an add-on package. However, controlling the axis breaks in the individual panels can be complicated, which is something we’d commonly want to do. Theme(strip.background = element_blank(), ggplot(datlong, aes(x = value, y = resp) ) +įacet_wrap(~variable, scales = "free_x", strip.position = "bottom") + I can use the facet strips to give the appearance of axis labels, as shown in this Stack Overflow answer. ggplot(datlong, aes(x = value, y = resp) ) + The argument scales = "free_x" allows the x axis scales to differ for each variable but leaves a single y axis.

Now I can use facet_wrap() to make a separate scatterplot of resp vs each variable. datlong = gather(dat, key = "variable", value = "value", -resp) Since the three variables are currently in separate columns we’ll need to reshape the dataset prior to plotting. One good option when we want to make a similar plot for different groups (in this case, different variables) is to use faceting to make different panels within the same plot. # 3 will go all the way across the bottom. # then plot 1 will go in the upper left, 2 will go in the upper right, and # If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), # - layout: A matrix specifying the layout. , or to plotlist (as a list of ggplot objects) Once the plot objects are set up, we can render them with multiplot. ) + ggtitle ( "Final weight, by diet" ) + theme ( legend.position = "none" ) # No legend (redundant in this graph) P 4 <- ggplot ( subset ( ChickWeight, Time = 21 ), aes ( x = weight, fill = Diet )) + geom_histogram ( colour = "black", binwidth = 50 ) + facet_grid ( Diet ~. P 3 <- ggplot ( subset ( ChickWeight, Time = 21 ), aes ( x = weight, colour = Diet )) + geom_density () + ggtitle ( "Final weight, by diet" ) # Fourth plot

2, size = 1 ) + ggtitle ( "Fitted growth curve per diet" ) # Third plot

P 2 <- ggplot ( ChickWeight, aes ( x = Time, y = weight, colour = Diet )) + geom_point ( alpha =. P 1 <- ggplot ( ChickWeight, aes ( x = Time, y = weight, colour = Diet, group = Chick )) + geom_line () + ggtitle ( "Growth curve for individual chicks" ) # Second plot Library ( ggplot2 ) # This example uses the ChickWeight dataset, which comes with ggplot2
