Grid of multiple ggplot2 plots which have been made in a for loop
I would be inclined to agree with Richie, but if you want to arrange them yourself:
library(gridExtra)
library(ggplot2)
p <- list()
for(i in 1:4){
p[[i]] <- qplot(1:10,10:1,main=i)
}
do.call(grid.arrange,p)
take a look at the examples at the end of ?arrangeGrob
for ways to eliminate the for loop altogether:
plots = lapply(1:5, function(.x) qplot(1:10,rnorm(10),main=paste("plot",.x)))
require(gridExtra)
do.call(grid.arrange, plots)
How to save multiple ggplot charts in loop for using grid.arrange
This could be solved by initiating a list
to store the plot objects instead of vector
p <- vector('list', N)
for(i in seq_len(N)) {
p[[i]] <- ggplot(...)
}
grid.arrange(p[[1]], p[[2]], ..., p[[N]], nrow = 4)
How to generate multiple ggplots using a for loop
Try with this:
library(ggplot2)
#Function does not return graph
for (i in list){
var <- sym(i)
print(ggplot(data = test_df, aes(x= DateTime.lub, y = !!var))+
geom_line(aes(colour = Step))+
ggtitle(paste0('plot_',i)))
}
Related Topics
How to Coerce a List Object to Type 'Double'
How to Use a List as a Hash in R? If So, Why Is It So Slow
Stacked Bars Within Grouped Bar Chart
Standard Deviation in R Seems to Be Returning the Wrong Answer - am I Doing Something Wrong
Function to Split a Matrix into Sub-Matrices in R
How to Complete Missing Factor Levels in Data Frame
R: Ggplot2 Barplot and Error Bar
Greek Letters, Symbols, and Line Breaks Inside a Ggplot Legend Label
Test If an Argument of a Function Is Set or Not in R
Using Parallel's Parlapply: Unable to Access Variables Within Parallel Code
How to Change the Figure Caption Format in Bookdown
Rstudio Shiny Error: There Is No Package Called "Shinydashboard"
Replace Empty Values with Value from Other Column in a Dataframe