I\'m having a hard time trying to create a function with a for loop that takes the columns in a data frame and creates different plots based on the column name.. I have read
The following works.
You were looping along all columns including column "DATE", which is supposed to be the x axis and the loop variable was integer so in the plot's aesthetic y = i was an integer, not a column name.
Note that I call windows() to open a new graphic window. Remove this if not needed.
Plot_Graph <- function(DF, na.rm = TRUE){
nm = names(DF)[-1]
for (i in nm) {
g <- ggplot(DF, aes(x = DATE, y = get(i))) +
geom_point()
windows()
print(g)
}
}
Plot_Graph(philly_df_new)