GGPLOT线图上有一个组的线
我正在制作几个组的线图,并想进行可视化,其中一组线被突出显示
ggplot(df) + geom_line(aes(x=timepoint ,y=var, group = participant_id, color=color)) +
scale_color_identity(labels = c(red = "g1",gray90 = "Other"),guide = "legend")
,但是,组线被其他组线部分遮盖了
我如何才能始终使这些行始终在顶部上其他组线?
I am making a line plot of several groups and want to make a visualization where one of the groups lines are highlighted
ggplot(df) + geom_line(aes(x=timepoint ,y=var, group = participant_id, color=color)) +
scale_color_identity(labels = c(red = "g1",gray90 = "Other"),guide = "legend")
However, the group lines are partially obscured by the other groups lines
How can I make these lines always on top of other groups lines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是在不同层上绘制灰色和红色的群体。
首先,让我们尝试使用虚拟数据集复制问题:
现在,我们应用您的绘图代码:
>你的情节。相反,如果我们在不同的层中绘制,我们将获得:
在2022-06-20创建的 reprex package (v2.0.1)
The simplest way to do this is to plot the gray and red groups on different layers.
First, let's try to replicate your problem with a dummy data set:
Now we apply your plotting code:
This looks broadly similar to your plot. If instead we plot in different layers, we get:
Created on 2022-06-20 by the reprex package (v2.0.1)
您可以使用因子重新启示,将感兴趣的线(-s)带到前线。
首先,让我们按原样绘制数据,其中红线部分被其他人隐藏。
现在,让我们通过将P_1置于最后一个因素级别来将P_1置于前面。
You can use factor releveling to bring the line (-s) of interest to front.
First, let's plot the data as is, with the red line partly hidden by others.
Now let's bring p_1 to front by making it the last factor level.