我使用的是R包ggpmisc。想知道如何在回归方程中加入y,或者如何在回归方程中得到自定义响应和解释变量名。
library(ggplot2)
library(ggpmisc)
df <- data.frame(x1 = c(1:100))
set.seed(12345)
df$y1 <- 2 + 3 * df$x1 + rnorm(100, sd = 40)
p <- ggplot(data = df, aes(x = x1, y = y1)) +
geom_smooth(method = "lm", se=FALSE, color="black", formula = y ~ x) +
stat_poly_eq(formula = y ~ x,
aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~")),
parse = TRUE) +
geom_point()
p

发布于 2016-02-23 19:20:47
我将关闭粘贴在其中的y的默认值,并构建自己的公式。例如
ggplot(data = df, aes(x = x1, y = y1)) +
geom_smooth(method = "lm", se=FALSE, color="black", formula = y ~ x) +
stat_poly_eq(formula = y ~ x, eq.with.lhs=FALSE,
aes(label = paste("hat(italic(y))","~`=`~",..eq.label..,"~~~", ..rr.label.., sep = "")),
parse = TRUE) +
geom_point()我们使用eq.with.lhs=FALSE关闭y=的自动包含,然后将hat(y)放在前面(带有等号)。注意,格式来自?plotmath帮助页面。

https://stackoverflow.com/questions/35585813
复制相似问题