Plotting Multiple Time Series Graphs in a Grid

I am having trouble getting several time series plots to display as a grid for direct comparison. This is my code for one plot:

#Station D7

D7_Chla <- ggplot(Dataset_D7, aes(Date, Chla)) +
geom_line(na.rm=TRUE) +
geom_point(na.rm=TRUE, color="blue", size=1) +
ggtitle("Station D7") +
xlab("Date") + ylab("Chloraphyll-a (Chl-a) (mg/L)") +
scale_x_date(limits = as.Date(c("2009-10-01","2019-09-31")),breaks = date_breaks("years"),
labels = date_format("%Y")) +
theme(plot.title = element_text(lineheight=.8, face="bold",
size = 20)) +
theme(text = element_text(size=12))

I am trying to display this plot in a grid with 10 other plots named C3A_Chla, P8_Chla, D19_Chla, D28A_Chla, D8_Chla, D6_Chla, C10A_Chla, MD10A_Chla, D26_Chla, and D4_Chla

I tried several different options by searching on google and nothing seems to work. I created data frames for each station, although it may be easier to use my master frame and select the variables I would like to use (I do not use all stations from the master frame)? I either get errors or am able to only view the titles of each plot. Each plot can be assigned a letter rather than having a station title if that is easier to format. Another issue may be the inclusion of x and y formatting for each plot rather than formatting it for all plots in the grid at one.
I have tried ggdraw(), a command through the lubridate library...I think it may have just been aggregate() ...I deleted the code and can't quite recall, and grid()

p1 <- ggplot(mtcars) + 
  geom_point(aes(mpg, disp)) + 
  ggtitle('Plot 1')

p2 <- ggplot(mtcars) + 
  geom_boxplot(aes(gear, disp, group = gear)) + 
  ggtitle('Plot 2')

p3 <- ggplot(mtcars) + 
  geom_point(aes(hp, wt, colour = mpg)) + 
  ggtitle('Plot 3')

p4 <- ggplot(mtcars) + 
  geom_bar(aes(gear)) + 
  facet_wrap(~cyl) + 
  ggtitle('Plot 4')

p1 / (p2 | p3)

Created on 2020-03-23 by the reprex package (v0.3.0)

1 Like

I tried installing patchwork using install.packages() but it returns an error message that says:
Error in install.packages : object 'patchwork' not found

It's on CRAN, so it should install. Please don't be affronted if I ask if you quoted the package.


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.