I have this dataframe
DF
Person Day Activity Count
<chr> <chr> <chr> <dbl>
1 Per. 1 Mon Eat 2
2 Per. 1 Thu Sleep 1
3 Per. 1 Sat Work 6
4 Per. 2 Mon Eat 2
5 Per. 2 Thu Sleep 3
6 Per. 2 Sat Work 2
7 Per. 3 Mon Eat 4
8 Per. 3 Thu Sleep 4
9 Per. 3 Sat Work 3
I would like to plot a bar plot with Activity looped over Person and Day to get 9 plots. (Person 1 - Mon, Person 1 - Thu, Person 1 - Sat, Person 2 - Mon etc.)
Firstly, I have two lists with unique values
Person <- unique(DF$Person)
Day <- unique(DF$Day)
Secondly, loop
for (i in seq_along(Person[i] )) {
for (j in seq_along(Day[j] )) {
plot <- ggplot(subset(DF, DF$Person==Person[i]),DF$Day==Day[j]),
aes(Activity, Count)) }}
But this doesn't work. Is there a solution?
