library(patchwork)
library(ggplot2)
cell_measurements = read_csv(random.csv)
measurement_types = col_names(cell_measurements)[5:9]
plot_list = list()
for (i in 1:5){
plot_list[[i]] = ggplot(cell_measurements, aes(sapply(Injury, as.character), eval(parse(text = measurement_types[i])))) +
geom_boxplot(aes(fill=Animal)) +
labs(x ='Injury', y = measurement_types[i])
}
wrap_plots(plot_list)
Example data:
Animal = c(dog, dog, dog, rabbit, rabbit, rabbit)
Injury = c(0,1,0,1,0,1)
Measurement1 = c(0.1,0.2,-0.8,1.5,1.2,1.3)
Measurement2 = c(0.1,0.5,-0.9, -1.4, 1.6, -0.5)
What I expected to get were five different plots neatly arranged, instead, all five plots here are the same. They have the right labels on the x and y axis but the box plots look exactly the same.
Also, tried to each plot individually and then do wrap_plots
which worked fine. Just doesn't work when I use the for loops.