I want to produce bar plots for each column in a data frame.
I tried the following code to produce plot for a single column and it's working fine.
ggplot(df, aes(colName, ..count..)) + geom_bar(aes(fill = colName), position = "dodge")
But it's not working if i put it in a for loop to produce plot for each column in the data frame.
for(col in names(df)){
print(col)
ggplot(df, aes(col, ..count..)) + geom_bar(aes(fill = col), position = "dodge")
}
I don't want to hard code the column names in the code and I don't want to develop a separate function.