r - Create lines parallel to my `geom_smooth(method = lm)` line
问题描述
library(tidyverse)
ggplot(mpg, aes(cty, hwy)) +
geom_point() +
geom_smooth(method = lm)
I would like two purple lines to run parallel to my geom_smooth(method = lm)
line. Each line should be 10 units away from the geom_smooth(method = lm)
line. One line would be above, and the other line below the geom_smooth(method = lm)
line.
How do I accomplish this?
解决方案
正如这个答案所暗示的那样,似乎没有一种自然的方式来转移一条线。然后我们可以做的是使用geom_smooth
具有不同偏移量的多个:
ggplot(mpg, aes(cty, hwy)) +
geom_point() +
lapply(c(-10, 0, 10), function(o)
geom_smooth(method = lm, formula = y + o ~ x))
推荐阅读
- google-apps-script - 即使我可以从 chrome 打开它,也无法使用 SpreadsheetApp.openByUrl(remoteUrl)
- powerbi - PowerBI 列中未显示全文
- python - 如何在 Python 中解析 JSON?
- android - 需要带有 ffmpeg java sdk 的 OpenCV
- javascript - 使用javascript随机改变颜色
- python - 保持多个 ssh 连接处于活动状态并在下一次函数调用时使用正确的连接
- python - 如何正确设置 LPRNet 模型的输入图像大小?'RuntimeError:张量的大小必须匹配,除了维度 1..'
- javascript - 无法在 Firebase 托管上使用带有 Angular 8 的第二个数据库
- mysql - 简单插入查询返回语法错误
- python - 比较两个列表中的每个元素