Can we neatly align the regression equation and R2 and p value?

前端 未结 3 1364
独厮守ぢ
独厮守ぢ 2020-12-18 05:37

What is the best (easiest) approach to add neatly to a ggplot plot the regression equation, the R2, and the p-value (for the equation)? Ideally it should be

3条回答
  •  一生所求
    2020-12-18 05:49

    I have updated 'ggpmisc' to make this easy. Version 0.3.4 is now on its way to CRAN, source package is on-line, binaries should be built in a few days' time.

    library(ggpmisc) # version >= 0.3.4 !!
    
    ggplot(mtcars, aes(x = wt, y = mpg, group = cyl)) +
      geom_smooth(method="lm")+
      geom_point()+
      stat_poly_eq(formula = y ~ x, 
                   aes(label = paste(..eq.label.., ..rr.label.., ..p.value.label.., sep = "*`,`~")), 
                   parse = TRUE,
                   label.x.npc = "right",
                   vstep = 0.05) # sets vertical spacing
    

提交回复
热议问题