![]() I’ll remake the combined plot, this time removing the y axis elements from all but the first plot. cowplot::plot_grid(elevplot,īut we want a single shared y axis, not a separate y axis on each plot. 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.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |