如何使用 stat_smooth(method ='lm')使标签(道路)的每一行回归?我无法用此代码获得任何行。.
library(ggplot2)
p1<-ggplot(data=a, aes(x = date_cut, y = price_mul, color=road)) +
geom_point(size=1.5) + stat_smooth(method = 'lm') +
scale_x_discrete(limits = c("06", "07", "08", "09", "10", "11", "12", "01", "02", "03", "04", "05")) +
ylim(0, max(a$price_mul)) + labs(x = "month (2018.06 ~ 2019.05)", y = "price", size = 10) +
theme_calc() +
scale_color_discrete(name="road") +
theme(plot.title = element_text(face = "bold", hjust = 0.5, size = 16, color = "black"))
答案 0 :(得分:0)
您是否尝试过使用geom_smooth(method = "lm")
。这是使用虹膜数据集的示例:
iris%>%
ggplot(aes(x = Petal.Length, y = Petal.Width, color = Species))+
geom_point()+geom_smooth(method = "lm")