Very often I have a dataset from which I need to make multiple graphs where the x-value stays the same but the y-value changes.
For example, the df code below has 1 factor variable, year, and 3 measures.
I need to make 3 plots where the only thing that's changing is the value for y.
library(dplyr)
library(ggplot2)
years <- c(2012,2013,2014,2015)
count <- c(20,25,28,31)
spend <- c(300,320,310,341)
prop <- c(.7,.3,.5,.8)
df <- data.frame(years,count,spend,prop)
ggplot(df,aes(x = years, y = count)) +
geom_col()
ggplot(df,aes(x = years, y = spend)) +
geom_col()
ggplot(df,aes(x = years, y = prop)) +
geom_col()
This is a very simple version, my actual graphs are much more elaborate.
So far I've used a loop to generate multiple graphs, I've created a function which is then executed in a loop and I've done the simple copy/paste.
Is some other, more formal, way of doing this? Either with dplyr and ggplot or anything else?
Thank you

