Modifying the code in R to make a loop function for plots in R -


i wondering how can make loop function have scatter plot of each variable vs gear , carb in 1 page. mean scatter plot of mpg va gear , scatter plot of mpg va carb in 1 page. again scatter plot of cyl vs gear , cyl vs carb in 1 page. since have many variables in real sets not want use code;

attached (mtcars) b1<-mtcars[,c(1,10,11)] plot1 <- b1 %>% gather(-mpg, key = "var", value = "value") %>% ggplot(aes(x = mpg, y = value))+ facet_wrap(~ var, scales = "free") + geom_point() + stat_smooth()   b2<-mtcars[,c(2,10,11)] plot2 <- b2 %>% gather(-cyl, key = "var", value = "value") %>% ggplot(aes(x = cyl, y = value))+ facet_wrap(~ var, scales = "free") + geom_point() + stat_smooth()  

and on.

                   


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -