I am making a plot with data from an incomplete factorial design. Due to the design, I have different length for the manual scale for colour and the manual scale for fill. Thus, I get two legends. How could I delete one of them or even better combine them?
I have looked at those questions:
Merge separate size and fill legends in ggplot
How to merge color, line style and shape legends in ggplot
How to combine scales for colour and size into one legend?
However, the answers did not help me as they did not handle incomplete designs.
Here is some example data and the plot I produced so far:
#Example data
Man1 <- c(25,25,30,30,30,30,35,35,40,40,40,40,45,45)
Man2 <- c(25,25,30,30,40,40,35,35,40,40,30,30,45,45)
DV <- c(24.8,25.2,29.9,30.3,35.2,35.7,34,35.1,40.3,39.8,35.8,35.9,44,44.8)
Data <- data.frame(Man1,Man2,DV)
#Plot
ggplot(data = Data, aes(x = Man1, y = DV, group=as.factor(Man2), colour=as.factor(Man2))) +
theme_bw() +
geom_abline(intercept = 0, slope = 1, linetype = "longdash") +
geom_point(position = position_dodge(1))
geom_smooth(method = "lm", aes(x = Man1, y = DV, group=as.factor(Man2), fill=as.factor(Man2))) +
scale_colour_manual(name = "Man2", values=c('grey20', 'blue','grey20','tomato3', 'grey20')) +
scale_fill_manual(name = "Man2", values=c('blue','tomato3'))
This gives me the following picture:
ggplot of incomplete design with two legends
Could someone give me a hint how to delete one of the legends or even better combine them? I would appreciate it!