I am trying to merge the legends of a plot, but I can't figure out how. I looked up many examples, but in these examples people build the plots from one dataframe. My plot is build from four dataframes. I tried merging these dateframes with the merge and rbind function, but I can't figure out how to do it correctly.
Is it possible to merge the legends without merging the dataframes?
This is my code
fig_ObjPlur_ASSenTD <- ggplot(subset(gazetarget_ObjPlur_ASS)) +
geom_line(data=gazetarget_ObjPlur_ASS,aes(x=Time, y=Targetgaze, color="Target", linetype="ASS"), size=1) +
geom_line(data=gazeother_ObjPlur_ASS,aes(x=Time, y=Othergaze, color="Distractor",linetype="ASS"), size=1) +
geom_line(data=gazetarget_ObjPlur_TD,aes(x=Time, y=Targetgaze, color="Target", linetype="TD"), size=1) +
geom_line(data=gazeother_ObjPlur_TD,aes(x=Time, y=Othergaze, color="Distractor", linetype="TD"), size=1) +
scale_color_manual(name = "Condition & Group", values=c("blue","red")) +
scale_linetype_manual(name = "Condition & Group", values=c(1,2)) +
theme(legend.key.width=unit(2.5,"line"))
fig_ObjPlur_ASSenTD + ggtitle("Looks to target vs. distractor picture") +
xlab("Time in milliseconds from sentence start") +
ylab("Proportion of looks") +
xlim(0,3000)
Which gives me this graph. Instead of two legends, I want one legend with 4 points:
- Target ASD (blue solid line)
- Distractor ASD (red solid line)
- Target TD (blue dashed line)
- Distractor TD (red dashed line)
My dataframes look like this:
Help would be appreciated!