ggplot2:将一行移到最前面,但是保存颜色 [英] ggplot2: Bring one line to the front, but save the colors

查看:76
本文介绍了ggplot2:将一行移到最前面,但是保存颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下代码:

library(ggplot2)
foo <- data.frame(x=1:10,A=1:10,B=10:1)
ggplot(melt(foo,id.vars="x"),aes(x,value,color=variable))+geom_line(size=5)

我想将红线(A)放在B的顶部(请参见交叉点),而颜色和它们在图例中出现的顺序不会改变.有什么办法吗?

I want to bring the red line (A) to the front, on top of B (see the cross point), while the colors and the order they appear in the legend do not change. Is there any way?

推荐答案

尝试一下,

last_plot() + aes(group=rev(variable))

这篇关于ggplot2:将一行移到最前面,但是保存颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆