【发布时间】:2019-03-04 18:09:18
【问题描述】:
我正在使用来自不完整因子设计的数据绘制图。由于设计的原因,我对颜色的手动刻度和填充的手动刻度有不同的长度。因此,我得到了两个传说。我怎样才能删除其中一个甚至更好地合并它们?
我看过这些问题:
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?
但是,答案对我没有帮助,因为它们没有处理不完整的设计。
这是一些示例数据和到目前为止我制作的图:
#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'))
这给了我以下图片:
ggplot of incomplete design with two legends
有人可以给我一个提示,如何删除其中一个图例,或者更好地组合它们吗?我会很感激的!
【问题讨论】: