[英]R weird behavior with geom_abline()
我正在使用这段代码:
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_smooth(method = "lm", se = FALSE, color = '#376795', size = 1) +
geom_abline(intercept = 34.232237, slope = -4.539474, linetype = 'dashed')
我得到这张图:
然后我用 command + shift + c 注释掉中间那行代码
ggplot(mtcars, aes(x = wt, y = mpg)) +
# geom_smooth(method = "lm", se = FALSE, color = '#376795', size = 1) +
geom_abline(intercept = 34.232237, slope = -4.539474, linetype = 'dashed')
我得到一个没有任何线条的图表。 geom_abline() go 的行在哪里?
然后我切换顺序并小心 + 号......
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_abline(intercept = 34.232237, slope = -4.539474, linetype = 'dashed') +
geom_smooth(method = "lm", se = FALSE, color = '#376795', size = 1)
两条线都回来了。 所以 geom_abline() 的代码看起来不错,对吧?
所以我然后注释掉中间一行:
ggplot(mtcars, aes(x = wt, y = mpg)) +
# geom_abline(intercept = 34.232237, slope = -4.539474, linetype = 'dashed') +
geom_smooth(method = "lm", se = FALSE, color = '#376795', size = 1)
geom_smooth() 在那里但不是 abline。 我真的对这种行为感到困惑。 我真的只想要 abline 而不是 smooth 但这不起作用:
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_abline(intercept = 34.232237, slope = -4.539474, linetype = 'dashed')
一定有一个简单的原因。 而且 - 为什么行为不一致? 感觉像是一个错误,因为相同的代码在一个地方似乎可以工作,而在另一个地方却不行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.