R 在图形上显示方程式(ggplot2)

R 在图形上显示方程式(ggplot2),r,R,我是R新手,使用以下代码绘制图形: p <- ggplot(data = data, aes(x, y, color=group)) + geom_smooth(method = "lm", se=FALSE, formula = lineq) + stat_poly_eq(formula = lineq, eq.with.lhs = "italic(hat(y))~`=`~",

我是R新手,使用以下代码绘制图形:

p <- ggplot(data = data, aes(x, y, color=group)) +
     geom_smooth(method = "lm", se=FALSE, formula = lineq) + 
     stat_poly_eq(formula = lineq,
               eq.with.lhs = "italic(hat(y))~`=`~",
               aes(label = paste(..eq.label..)), 
               parse = TRUE) +         
     geom_point()
p试试下面的方法

library(ggpmisc)

p <- ggplot(data = data, aes(x = age, y = height, color=group)) +
     geom_smooth(method = "lm", se=FALSE, formula = lineq) + 
     stat_poly_eq(formula  = lineq,
               eq.with.lhs = "italic(height)~`=`~",
               eq.x.rhs    = "~italic(age)",
               aes(label   = paste(..eq.label..)), 
               parse = TRUE) +         
     geom_point()
库(ggpmisc)
P