library(grid)
library(gridExtra)
plot_freq <- function(arrs){
g <- list()
for(i in c(1:length(arrs))){
y_val <- get(arrs[i])
g[[i]] <- qplot(y = y_val, x = c(1,2,3,4,5))
print(g[[i]])
}
grid.arrange(grobs = g, ncol= 3)
}
a <- c(4,4,4,4,4)
b <- c(5,5,5,5,5)
c <- c(6,6,6,6,6)
plot_freq(c("a", "b", "c"))
Above code results in three same plots (same like last plot i.e. array c) in grid.arrange but if we plot them separately, they work fine. Any way I should change my code to get it working?