问题描述
我在ggplot2中有一个简单的图,并且想添加一条虚线的回归线。到目前为止,我有:
pre $ library $ g $ b $ ggplot ))+
geom_point()+
geom_smooth(method =lm,se = FALSE)+
theme_bw()
返回我想要的内容,但带有一条实线:
),linetype是geom_smooth理解的美学之一。
因此,您可以调整为使用 I have a simple plot in ggplot2 and want to add a dashed regression line. So far I have: Which returns what I want, but with a solid line: I want to make the line dashed. I think I should use A simple question, but I couldn't find a duplicate. As per the help page (see So, you can adjust to use 这篇关于用ggplot2中的geom_smooth绘制虚线回归线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! geom_smooth(method =lm,se = FALSE,linetype =dashed)$ c
$ p $ library(ggplot2)
ggplot(mtcars,aes(x = hp,y = mpg)) +
geom_point()+
geom_smooth(method =lm,se = FALSE,linetype =dashed)+
theme_bw()
library(ggplot2)
ggplot(mtcars, aes(x = hp, y = mpg)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
theme_bw()
scale_linetype_manual()
but my attempts have been hacky.?geom_smooth
), linetype is one of the aesthetics geom_smooth understands. geom_smooth(method = "lm", se = FALSE, linetype="dashed")
library(ggplot2)
ggplot(mtcars, aes(x = hp, y = mpg)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, linetype = "dashed") +
theme_bw()