Hello Team,
I create a csv file (mac2) to save parameter values. the file looks like:
y,c,f
hwy,cyl,hwy_cyl2
cty,class,cty_class2
Then I load the file into R and apply the parameters y, c, f in for loop, see
my code below:
library(ggplot2)
library(tidyverse)
library(readr)
mac2 <- read_csv("C:/temp/mac2.csv")
View(mac2)
for (i in seq(nrow(mac2))){
mpg %>%
filter(hwy <35) %>%
ggplot(aes(x = displ, y = get(y[i]), color = get(c[i]) )) +
geom_point()+
ylab(y[i]) +
guides(color = guide_legend(title = c[i]))
ggsave(paste0("c:/temp/",f[i],".jpg"),width = 9, height = 6, dpi = 1200, units
= "in")
}
but I got an error message: "Error in dots_list(..., title = title, subtitle =
subtitle, caption = caption, : object 'y' not found"
Does anyone know how to fix the problem?
Thanks,
Kai
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.