I am trying to plot linear regression and display corresponding equations and R squared. I used the #following code:
ch= factor (rep(c("c1", "c2", "c3", "c4"),3, each=4))
ch
tr= factor ((rep(c("dd", "ld", "dc"), each=16)), levels= c("dd","ld","dc"))
tr
fif= as.numeric ( c(13.55,13.92,10.78,11.5,14.6,13.86,12.49,11.25,15.35,14.39,13.14,9.27,14.67,10.14,13.31,11.66,
14.38,13.56,11.05,13.32,15.04,14.32,13.40,12.01,14.81,10.97,13.01,12.33,13.67,13.09,13.43,9.59,
5.51,13.79,12.55,11.92,8.41,12.80,13.19,12.04,12.19,15.78,14.04,14.43,12.53,14.83,14.38,12.77))
fif
fou = as.numeric( c(75.65,83.52,85.46,91.43,96.58,85.33,81.78,95.32,113.13,92.30,86.58,77.68,99.89,70.40,83.53,89.49,
79.04,82.97,80.18,93.98,93.67,83.59,99.07,104.56,95.74,77.40,91.91,107.04,77.76,87.77,90.66,86.81, 73.64,98.13,81.36,90.97,71.96,73.90,76.19,99.90,83.51,85.37,82.29,88.77,81.37,84.76,94.10,83.59))
fou
dt = as.numeric(c(rep(c(0.00,5.15,12.95,21.42), 4),
rep(c(0.00,5.36,13.03,21.58), 4),
rep(c(0.00,6.07,16.33,24.09), 4))
)
dt
d.df = data.frame(ch, tr, dt, fif, fou)
d.df
d.df_dd = d.df[1:16, 1:5]
d.df_dd
d.df_ld = d.df[17:32, 1:5]
d.df_ld
d.df_dc = d.df[33:48, 1:5]
d.df_dc
library(tidyverse)
library(ggpubr)
library(broom)
library(dplyr)
d_f_tf1_dd = d.df_dd %>%
filter(dt != 0)
d_f_tf1_dd
I used the package ggpmisc v 0.5.3 to display equations and R squared. The code works until a plot, #where it stops working: #plot that works
library(ggpmisc)
p_dd14= ggplot(data=d_f_tf1_dd, aes(dt, fou, color= ch)) +
geom_smooth(method="lm", se=F, linewidth= 1, aes(linetype= ch, colour= ch, group= ch))+
geom_point(aes(colour= ch, shape= ch), size= 3.5, alpha= .8) +
stat_poly_eq(
formula= y~x,
aes(label = paste(after_stat(eq.label),
after_stat(rr.label), sep = "\*plain(";")\~\~")),
label.x = "centre", label.y = "bottom", hjust="inward",
coef.digits = 3,
size=4,
vstep= 0.05,
parse=T
)
p_dd14
#plot with troubles
d_f_tf1_dc= d.df_dc %\>%
filter(dt != 0)
d_f_tf1_dc
p_14= ggplot(data=d_f_tf1_dc, aes(dt, fou, color= ch)) +
geom_smooth(method="lm", se=F, linewidth= 1, aes(linetype= ch, colour= ch, group= ch))+
geom_point(aes(colour= ch, shape= ch), size= 3.5, alpha= .8) +
stat_poly_eq(
formula= y~x,
aes(label = paste(after_stat(eq.label),
after_stat(rr.label),
sep = "\*plain(";")\~\~")),
label.x = "right", label.y = "bottom", hjust="inward",
coef.digits = 3,
size=4,
vstep= 0.05,
parse=T)
p_14
the following warnings appeared:
geom_smooth() using formula = 'y ~ x'
Warning messages: #1: In ci_f_ncp(stat, df1 = df1, df2 = df2, probs = probs) : #Upper limit outside search range. Set to the maximum of the parameter range. #2: Computation failed in `stat_poly_eq()` #Caused by error in `check_output()`: #! out[1] <= out[2] is not TRUE
Have you any suggestions on how to solve the issue? thank you for your availability