小编Wil*_*ll 的帖子

如何在具有相同"y"的行之间进行着色?

我花了几个小时在geom_polygon和geom_ribbon之间尝试,但我无法让它工作.我希望遮蔽两条线之间的区域(我研究了很多).看,图的两个轴都是数字,两条线共用同一个y轴,因此,我不能让它工作计算ymin也不能YMAX.有什么想法吗?我会完全欣赏它.这是我的代码:

ggplot(npsmelt,aes(Score,Unresolved)) + 
    geom_line(aes(linetype=Metric, color=Metric)) +
    theme(legend.position="top", legend.title = element_blank()) +
    geom_point(aes(color=Metric)) +
    theme(plot.caption=element_text(size=8, margin=margin(t=10))) + 
    scale_x_continuous(breaks=seq(54,70,1)) + 

    geom_ribbon(data=subset(npsmelt, 
         Score[Metric=="Old.NPS"]<Score[Metric=="New.NPS"]),
         aes(ymin =0, ymax =..y..), alpha=0.10)
Run Code Online (Sandbox Code Playgroud)

结果图: 在此输入图像描述

我的数据:

Unresolved  Metric  Score
    5   New.NPS 66.48
    6   New.NPS 65.32
    7   New.NPS 64.16
    8   New.NPS 63
    9   New.NPS 61.84
   10   New.NPS 60.68
    5   Old.NPS 68.5 
    6   Old.NPS 62.28
    7   Old.NPS 61.74
    8   Old.NPS 61.41
    9   Old.NPS 61.67
   10   Old.NPS 60.42
Run Code Online (Sandbox Code Playgroud)

dput:

structure(list(Unresolved = c(5L, 6L, 7L, 8L, 9L, 10L, 5L, 6L, 
7L, 8L, …
Run Code Online (Sandbox Code Playgroud)

r area ggplot2

3
推荐指数
1
解决办法
124
查看次数

标签 统计

area ×1

ggplot2 ×1

r ×1