Adding legend to ggplot when lines were added manually

I have a plot in ggplot with 4 separate lines that I have added with a separate geom_line() argument. I would like to add legend but scale_colour_manual doesn't work in this case. What is the proper way to add legends when I added the variables separately? Here's my code: ggplot(proba[108:140,], aes(c,four)) + geom_line(linetype=1, size=0.3) + scale_x_continuous(breaks=seq(110,140,5)) + theme_bw() + theme(axis.line = element_line(colour = "black", size=0.25), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.border = element_blank(), panel.background = element_blank()) + theme(axis.text.x = element_text(angle = 0, hjust = +0.5, size=6,color="black")) + theme(axis.text.y = element_text(angle = 0, hjust = -100, size=6, color="black")) + theme(axis.ticks=element_line(colour="black",size=0.25)) + xlab("\nTime-steps") + ylab("Proportion correct\n") + theme(axis.text=element_text(size=8),axis.title=element_text(size=8)) + geom_line(aes(c,three), size=0.2, linetype=2) + geom_line(aes(c,one),linetype=3, size=0.8, colour="darkgrey") + geom_line(aes(c,two), linetype=1, size=0.8, colour="darkgrey")
Can you post your code? Setting color="Line Name" in the call to aes should work.

以上就是Adding legend to ggplot when lines were added manually的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏