0

Graphs are printed the same I have tried many ways but all my plots printed out the same. When I tried using the for-loop and ggplot (without marrangeGrob), the graphs are different but they are printed out separate, while I want it to print out 4 graphs on each page. Does anyone know how to do it? Here is the written code:

char_var <- select_if(train,is.character)
#names(char_var)
library(gridExtra)
plot_char <- list()
for (i in 1:43 ) {
        plot_char[[length(plot_char)+1]]= ggplot(data=train,mapping= aes(x= char_var[,i], y = SalePrice)) + xlab(i)+ geom_boxplot()  
}

marrangeGrob(grobs = plot_char, nrow = 2, ncol=2)

enter image description here

teunbrand
  • 33,645
  • 4
  • 37
  • 63
  • 2
    I think you might want `aes_string(x= char_var[,i], y = "SalePrice")` instead of your current `aes()`. – teunbrand Apr 24 '20 at 21:08
  • Thank you for your suggestion. When I changed to aes_string, it said "Error: More than one expression parsed". A suggestion to fix this error is changing back to aes() – Giang Nguyen Apr 25 '20 at 00:31

0 Answers0