My data
ID | Time | Score | Var1 | Var 2 | Var 3 |
---|---|---|---|---|---|
1 | 1 | 100 | 1 | 2 | 1 |
1 | 2 | 150 | 1 | 2 | 1 |
2 | 1 | 200 | 2 | 3 | 4 |
2 | 2 | -10 | 2 | 3 | 4 |
2 | 3 | -70 | 2 | 3 | 4 |
3 | 1 | 100 | 1 | 2 | 2 |
3 | 2 | 200 | 1 | 2 | 2 |
I want to make a ggplot that combines all the variables together. Y variable is = score. X variable is = Time. and for each categorical variable (i.e., var1, var2) I want to see the effect for each level.
My code for one Graph:
var1_graph=ggplot (DB, aes(Time, Score, group_by = ID))+
facet_wrap(~var1)+
geom_smooth()+
theme_bw()
#####Var2
var2_graph = ggplot (DB, aes(Time,Score, group_by=ID))+
facet_wrap(~var2)+
geom_smooth()+
theme_bw()
################
ggarrange(var1_graph, var2_graph, labels = c("A","B"),
ncol = 1, nrow = 2).
But this isn't what I want because I want them to be in same plot and not to combine multiple plots.
Can do this using a "Pivot_longer function"?
Thanks!
dput(DB)