【发布时间】:2016-05-22 01:11:43
【问题描述】:
我不知道如何获得我使用函数 geom_smooth 绘制的线性回归的回归线方程、r^2 和 p 值。
这是我的代码:
g <- ggplot(data=data.male, aes(x=mid_year, y=mean_tc, colour=data.male$survey_type))
g <- g + geom_point(shape = 20, size =2)
g <- g + geom_smooth(method=lm, na.rm = FALSE, se = TRUE, aes(group=1), colour = "black")
g <- g + theme_gray(base_size=24)
g <- g+ xlab("Year")
g <- g + ylab("Mean serum total cholesterol (mmol/L)")
g <- g + theme(legend.position="bottom")
g <- g + scale_y_continuous(limits=c(3.5,6.5), breaks=c(3.5,4,4.5,5,5.5,6,6.5))
g <- g + scale_x_continuous(limits=c(1980,2015), breaks=c(1980,1990,2000,2010))
g <- g + scale_colour_manual(name = "Survey Type", values= c("Red", "Blue", "Green"))
g
[1]:
【问题讨论】:
-
正如@Spacedman 在他的回答中所说,为什么不自己拟合模型并提取必要的数据?
-
如果您看到答案here,您还会看到它在内部也使用
lm。 -
对不起@BenBolker 你的意思是即使我不使用
lm来适应情节但之后使用此代码行fit1 <- lm(mean_tc ~ mid_year, data = data.male) summary(fit1)它会显示与我从行中获得的相同的统计信息在 ggplot2 中? -
是的(正如@Spacedman 建议的那样)
标签: r ggplot2 linear-regression