[R] How to add "slope" in the scatter plot

Marna Wagley m@rn@@w@g|ey @end|ng |rom gm@||@com
Fri Feb 11 06:25:24 CET 2022


Hi R users,
I was trying to add slope, R2 and p value in the scatter plot, but I was
able to add only r2 and p value but not slope in the example data using the
following code. Would you mind checking the code?

daT<-structure(list(x = c(59.9, 96.4, 91.2, 51.4, 11.8, 38.3, 65,
38.3, 35.6, 48.2, 15, 24.6, 60.9), y = c(77.9, 51.8, 53.8, 1.8,
84.7, 49.6, 21.2, 39.5, 22.7, 71, 16.5, 85.8, 10.7)),
row.names = c(NA,-13L), class = "data.frame")

formula <- y ~ poly(x, 1, raw = TRUE)
ggplot(daT, aes(x= x, y=y, group=1))+
  geom_point(size=0, alpha=0.3, colour="pink")+geom_smooth(method =
"lm",linetype="dashed",
formula = formula, se = T, size = 2)+stat_poly_eq(formula = y ~ x,
aes(label = paste(..coef.., ..rr.label..,..p.value.label.., sep = "*`,`~")),
parse = TRUE,label.x.npc = "right", vstep = 0.05, size = 5)

thanks,
MW

	[[alternative HTML version deleted]]



More information about the R-help mailing list