[英]Receive the equation of the stat_smooth in ggplot2 R mtcars example
Hi I would like to know how can I retrieve the equation of stat_smooth either in the ggplot2 or in a vector or somewhere else. 嗨,我想知道如何在ggplot2或矢量或其他地方检索stat_smooth的等式。 the code that I am using is:
我正在使用的代码是:
p <- ggplot(data = mtcars, aes(x = disp, y = drat))
p <- p + geom_point() + stat_smooth(method="loess")
p
Thanks 谢谢
The ggpmisc
package can be very usefull. ggpmisc
软件包可能非常有用。 However, it will not work with loess as loess doesn't give a formula. 但是,它不适用于黄土,因为黄土没有给出公式。 See here: Loess Fit and Resulting Equation
参见此处: 黄土拟合和所得方程
library(ggplot2)
library(ggpmisc)
p <- ggplot(data = mtcars, aes(x = disp, y = drat)) +
geom_point() +
geom_smooth(method="lm", formula=y~x) +
stat_poly_eq(parse=T, aes(label = ..eq.label..), formula=y~x)
p
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.