虽然图中显示了不同的颜色,但图例仅显示一种颜色。我的目标是按照原样展示传奇。此外,我 NOT 希望使用21到25之间的形状。我想使用不同的形状,例如形状= 2。
这是源代码:
fixtureUpdate = StraightredFixture(fixtureid=fixture['Id'],
...
soccerseason_id = 1025)
# ^^^
这是输出。我们可以看到第二行#catsM dataset is in MASS package that is shipped by CRAN
testM<-catsM
testM[1:10,"Sex"] <- "F"
ggplot(testM,aes(Bwt,Hwt)) +
geom_point(aes(color=Sex), shape = 2) +
geom_smooth(method = "glm", se = FALSE,
aes(linetype = "glm line"), color = "red") +
geom_smooth(method = "lm", span = 0.5,
aes(linetype = "lm line"), color = "yellow") +
scale_color_manual(values = c("magenta","black"))
的颜色代码覆盖了lm
的红色。有没有解决这个问题?我很感激你的想法。
我发布了dput():
glm
答案 0 :(得分:3)
我还没有完全掌握ggplot2传奇的所有怪癖,但是如果你想强制它,guides
选项将允许你手动设置它:
testM<-catsM testM[1:10,"Sex"] <- "F" ggplot(testM,aes(Bwt,Hwt)) + geom_point(aes(color=Sex), shape = 2) + geom_smooth(method = "glm", se = FALSE, aes(linetype = "glm line"), color = "red") + geom_smooth(method = "lm", span = 0.5, aes(linetype = "lm line"), color = "yellow") + scale_color_manual(values = c("magenta","black")) + guides(linetype = guide_legend(override.aes = list(color = c("red", "yellow"))))
答案 1 :(得分:0)
对于离散变量,将美学映射到shape
是另一种选择。在设计美学和美国时,不确定它有多好:
ggplot(testM,aes(Bwt,Hwt)) +
geom_point(aes(shape= Sex)) +
geom_smooth(method = "glm", se = FALSE,
aes(linetype = "glm", color = 'glm')) +
geom_smooth(method = "lm", span = 0.5,
aes(linetype = "lm", color ='lm'), size = 4) +
scale_linetype_discrete(name = "Method") +
scale_color_manual(name = "Method", values = c('red', 'yellow'))