Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 创建与我的“geom_smooth(method=lm)`线平行的线_R_Ggplot2 - Fatal编程技术网

R 创建与我的“geom_smooth(method=lm)`线平行的线

R 创建与我的“geom_smooth(method=lm)`线平行的线,r,ggplot2,R,Ggplot2,我想要两条紫色线平行于我的geom_平滑(method=lm)线。每条线应距离geom_平滑(方法=lm)线10个单位。一条线在上方,另一条线在geom_平滑(method=lm)线下方 我如何做到这一点?正如我所建议的,似乎没有一种自然的方式来改变路线。然后,我们可以使用具有不同偏移量的多个geom_smooth: library(tidyverse) ggplot(mpg, aes(cty, hwy)) + geom_point() + geom_smooth(method =

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

我如何做到这一点?

正如我所建议的,似乎没有一种自然的方式来改变路线。然后,我们可以使用具有不同偏移量的多个
geom_smooth

library(tidyverse)
ggplot(mpg, aes(cty, hwy)) + 
  geom_point() + 
  geom_smooth(method = lm)

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