I am trying to create multiple exploratory scatterplots from a big dataset using a for loop. My x will always be the same (Gender), but for my y I want to loop through all of the columns. In the graph, I want the x-axis label to be Gender and the y-axis label to be whatever column of the data the loop is on.
Here is the code:
Library (ggplot)
for (i in df_red){
g = ggplot(data = df_red) +geom_point (mapping = aes(x=df_red$Gender, y= i, colour = factor(df_red$Group_New)))
g = g +labs( x= 'Gender' , y = i, colour = 'Group') + scale_color_manual(labels =c('1', '2', '3'), values = c('1', '2', '3'))
print(g)}
When I run the loop, the graphs look great, all of the data points are there and the X axis and legend are accurate. My problem is the y axis is labeled with the first data point of the column (e.g, 7.25) instead of the column name.
I sort of understand why it's doing this, but I have no idea what I need to change in order to make this work so I know which column I'm looking at in a given graph.
Any help is much appreciated, I am pretty new to R and feeling lost.