I'm trying to write the code to use my dataset and make a new graph for each column of a dataset, rather than have to write out a new value for y each time in the code.
I have a dataset where each row is a person, each column is a measurement in the blood (ie, insulin, glucose, etc). I have a few extra columns with descriptive categories that I"m using for my groups (ie lean, obese). I'd like to make a graph for each of those column measurements (ie, one graph for insulin, another for glucose, etc). I have 90 different variables to cycle through.
I've figured out how to a boxplot for each of these, but can't figure out how to have the code "loop"? so that I don't have to re-write the code for each variable.
Using the mtcars dataset as an example, I have it making a graph where the y is disp, and then another graph where y = hp, and then y = drat.
data("mtcars")
#boxplot with individual points - first y variable
ggplot(data = mtcars, aes(x = cyl, y = disp)) +
geom_boxplot()+
geom_point()
#boxplot with individual points - 2nd y variable
ggplot(data = mtcars, aes(x = cyl, y = hp)) +
geom_boxplot()+
geom_point()
#boxplot with individual points - 3rd y variable
ggplot(data = mtcars, aes(x = cyl, y = drat)) +
geom_boxplot()+
geom_point()
How do I set this up so my code will automatically cycle through all of the variables in the dataset (I have 90 of them)?