I would like to loop through each factor (cell) level and make a separate plot. My code makes separate plots but I do not know how to add these into one figure...
My data: https://www.dropbox.com/s/cczbbka0xxj57z5/df.csv?dl=0
The code I am working with:
windows(width=18,height=10)
a=layout(matrix(c(1,2,3,4), nrow = 2, ncol = 2, byrow=T))
layout.show(a)
# create a list of cells in data to loop over
cell_list <- unique(df$cell)
# create for loop to produce ggplot2 graphs for each cell
for (i in seq_along(cell_list)) {
# create a plot for each cell
plot <-
ggplot(subset(df, df$cell == cell_list[i]),
aes(x=condition, y=test_variable, group = cell)) +
labs(x = "Cell", y = "test_variable") +
ggtitle(unique(df$cell)[i]) +
geom_line(size = 1)+
geom_point(size=2, shape=17) +
theme(legend.position = "none")
print(plot)
}