How to change the chart title dynamically in R?
问题 Here is an example using mtcars to split by a variable into separate plots. What I created is a scatter plot of vs and mpg by splitting the data set by cyl . First an empty list is created. Then I used lapply to loop through the values of cyl (4,6,8) and then filter the data by that value. After that I plotted the scatter plot for the subset and saved it to the empty list. library(dplyr) library(ggplot2) gglist <- list() gglist <- lapply(c(4,6,8), function(x){ ggplot(filter(mtcars, cyl == x))