【问题标题】:Create lines parallel to my `geom_smooth(method = lm)` line创建与我的 `geom_smooth(method = lm)` 线平行的线
【发布时间】:2019-01-21 12:30:49
【问题描述】:
library(tidyverse)
ggplot(mpg, aes(cty, hwy)) + 
  geom_point() + 
  geom_smooth(method = lm)

我想要两条紫色线平行于我的geom_smooth(method = lm) 线。每行应与geom_smooth(method = lm) 行相距10 个单位。一行在geom_smooth(method = lm) 行的上方,另一行在geom_smooth(method = lm) 行的下方。

我该如何做到这一点?

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    正如this answer 所建议的那样,似乎没有一种自然的方式来换行。然后我们可以做的是使用多个具有不同偏移量的geom_smooth

    ggplot(mpg, aes(cty, hwy)) + 
      geom_point() + 
      lapply(c(-10, 0, 10), function(o)
        geom_smooth(method = lm, formula = y + o ~ x))
    

    【讨论】:

      猜你喜欢
      • 2019-08-13
      • 2018-10-15
      • 2019-08-21
      • 1970-01-01
      • 1970-01-01
      • 2020-01-26
      • 2020-04-30
      • 1970-01-01
      • 2013-04-06
      相关资源
      最近更新 更多