My goal is to plot several dataframes (they all have the same structure) using ggplot2. I need to read a csv file so I get a single dataframe then I split it which gives me a list with my datframes.
Dataframe_A <- read.csv("mycsv.csv")
Dataframe_A_split <- split.data.frame(Dataframe_A, list(Dataframe_A$V1,Dataframe_A$V2), drop=TRUE)
Dataframe_A <- data.frame(y1 = c(1, 2, 3,4,5,6,7,9,0,1), y2 = c(1, 3, 3,4,7,6,14,9,7,1), y3 =c("Yes","No","No","Yes","No","No","Yes","No","No","No"), y4=c("A","A","B","A","A","B","A","A","B","A"))
Dataframe_A_split<-split.data.frame(Dataframe_A, list(Dataframe_A$y3, Dataframe_A$y4), drop=TRUE)
$No.A
y1 y2 y3 y4
2 2 3 No A
5 5 7 No A
8 9 9 No A
10 1 1 No A
$Yes.A
y1 y2 y3 y4
1 1 1 Yes A
4 4 4 Yes A
7 7 14 Yes A
$No.B
y1 y2 y3 y4
3 3 3 No B
6 6 6 No B
9 0 7 No B
I know I can use Dataframe_A_split[[1]] to get to the first dataframe but I have twenty dataframe in my list and using ggplot (to do a scatter plot for example) to loop through my list would be useful and easier to read. In my example I would end up with three graphs.




y3andy4?group_byandmutateorsummarisefromdplyr. If you need to plot the groups separately, use thecolourorfillaesthetic to give your groups different colours orfacet_*to physically separate the plots.ggplot2, then you can usedplyr::group_byanddplyr::doto plot them separately. This assumes that you are saving them elsewhere or rendering them iteratively within a document, and not hoping to look at them incrementally/interactively.purrrpackage will handle that nicely! Although in that case I would probably usenest.