I have really strange problem... I'm trying to create plots in a loop and put them to the list and after that drew them all on one page. when I do it:
for (i in 1:ncol(df)){
plot[[i]] <- ggplot(df, aes(x = df[,i], y=(..count..)/sum(..count..))) +
geom_bar(fill="#003366") +
labs(title = dfcolnames[i], x = "Variable Values", y = "Frequency")
}
return(multiplot(plotlist=plot, cols = 2))
I get 3 this same plots, but when I do it without for loop:
plot[[1]] <- ggplot(df, aes(x = df[,1], y=(..count..)/sum(..count..))) + geom_bar(fill="#003366") + labs(title = dfcolnames[1], x = "Variable Values", y = "Frequency")
plot[[2]] <- ggplot(df, aes(x = df[,2], y=(..count..)/sum(..count..))) + geom_bar(fill="#003366") + labs(title = dfcolnames[2], x = "Variable Values", y = "Frequency")
plot[[3]] <- ggplot(df, aes(x = df[,3], y=(..count..)/sum(..count..))) + geom_bar(fill="#003366") + labs(title = dfcolnames[3], x = "Variable Values", y = "Frequency")
return(multiplot(plotlist=plot, cols = 2))
I get correct plots (three different). I don't understand what is going on.... Any ideas?