2 different legends when defining labels with scale_color_manual and geom_ribbon

Hey,

I added to my line graph geom_ribbon(aes(x=Time, ymin=fixp-ci, ymax=fixp+ci, linetype=NA, fill=Fixated_Object), alpha=.2). Since I have defined manually in the same code chunk my labels new with the following command

scale_color_manual(labels = c("A", "B", "C","D"),
values=c("red","darkblue","#009E73","purple"))?

Here is the complete code chunk

ggplot(subset(Dataframe, Condition %in% c("SVO")),
aes(x=Time, y=fixp, group=Fixated_Object, color=Fixated_Object, linetype=Fixated_Object)) +
theme_light() +
labs(x="Time (ms)", y="Mean Fixation proportions") +
theme(legend.position="bottom") +
geom_line(lwd=1)+
annotate('text', x = 150, y = .5, label="ObjNoun Onset + 200 ms", angle=90) +
annotate('text', x = 907, y = .5, label="ObjNoun Offset + 200 ms", angle=90)+
geom_vline(xintercept = 200, linetype = "longdash") +
geom_vline(xintercept = 957, linetype = "longdash") +
scale_y_continuous(limits=c(0,.7),expand=c(0,0))+
scale_x_continuous(limits=c(0,1957))+
scale_color_manual(labels = c("A", "B", "C","D"),
values=c("red","darkblue","#009E73","purple"))+
geom_ribbon(aes(x=Time, ymin=fixp-ci, ymax=fixp+ci, linetype=NA, fill=Fixated_Object), alpha=.2)+
guides(linetype = "none")

Best

Found the solution:

define also scale_fill_manual(labels = c("A", "B", "C","D"),
values=c("red","darkblue","#009E73","purple"))+

and add fill=Fixated_Object

this brings the legends together!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.