0

I would like to create graphs for multiple variables and save the graphs without have to type the same code over and over.

Variables: Var1, Var2, Var3

vars <- c(   "Var1", "Var2", "Var3"   )
for (v in vars) {
Graph_v <-  D %>%                               
  ggplot(mapping = aes(x= X, y= v)) +   geom_point(aes(x= X, y= v)) +
  stat_summary(
    fun.data = mean_se,
    geom = "line", size = 1)
}

My main problem is to safe the single graphs under different names.

Thanks for your help. Hanna

R will only safe the latest graph created because the name of the graph does not change.

0

1 Answer 1

0

Are you just trying to save them in a list?

library(tidyverse)

vars <- c("cyl", "hp")

plot_list <- list()
for(i in seq_along(vars)){
  plot_list[[i]] <- ggplot(mtcars, aes(!!sym(vars[[i]]), mpg))+
    geom_point()
}

plot_list
#> [[1]]

#> 
#> [[2]]

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.