I have the following problem. In my case, I plot 7 different result lines (7 models). I need to group them in 4 groups (colors) and each one with a different point shape. My problem is that I'm unable to merge the legends. I tried several different options (labs, unifying legend titles, doing the interaction thing)
Here is my mock.code:
mock.df <- data.frame(vec.dat=1:49,
variable = c(rep('Mod01',7),rep('Mod02',7),rep('Mod03',7),rep('Mod04',7),rep('Mod05',7),rep('Mod06',7),rep('Mod07',7)),
value = floor(runif(49, min=7500, max=7800)),
group = c(rep('color01',28),rep('color02',7),rep('color03',7),rep('color04',7)))
p<-ggplot(mock.df, aes(x=vec.dat,
y=value,
group=variable)) +
geom_line(aes(linetype=group,color=group))+
scale_linetype_manual(values = c("dotted","longdash","solid","solid"))+
geom_point(aes(shape=variable,color=group),size=3)+
scale_color_manual(values=c("#999999", "#E69F00", "#56B4E9","#008f39"))+
scale_shape_manual(values=c(15, 16, 17,18,19,3,8))
p
In fact, linetype legend is missing in this image. What I'm looking for is one legend merging linetype ("dotted","longdash","solid","solid"), shape (15, 16, 17,18,19,3,8) and color ("#999999", "#E69F00", "#56B4E9","#008f39")
information. But, I'm unable to do it!
theme(legend.key.width = unit(2, 'cm'))
to extend the lines in the legend, you will see four different line types. Shape can't be merged because you have 4 colours and 4 linetype but 6 shapes. What are you trying to do? Can you manually draw the desired effect out? – Drumy