Hi,
I want to switch from linear regression to York regression in R. I found some information over GitHub - JENScoding/yorkregression: R package with York's regression but do not know how to apply it in ggplot
code.
If anyone knows how to apply York regression directly in ggplot, similar to how linear regression is applied, please let me know. I currently use code for plotting linear regression with ggplot,
AE33_NCORE_hourly %>%
ggplot(aes(x = (MAAP_BC_abs_637), y=(AE33_Tabs_660),color="blue")) +
geom_point(size=2,alpha=0.9, color="blue", alpha = 0.3, shape = 1) +
geom_smooth(method=lm, size=0.3) +
geom_abline(slope = 1, intercept = 0, linetype = "dashed", color = "black") + # Add 1:1 line
labs(title= "") +
ylim(0,50)+ xlim(0,50)+
theme(legend.text=element_text(size=14)) +
theme(axis.title = element_text(face="plain",size=16,color="black"),axis.text=element_text(size=16,face="plain", color="black")) +
theme(plot.title = element_text(lineheight=.8, face="plain", size=14)) +
theme(legend.key.height = unit(0.4, "inch"))+
theme(legend.key.width = unit(0.1, "inch"))+
xlab(bquote(MAAP ~ abs[`(total,637)`]~ '('*Mm^-1*')')) +
ylab(bquote(AE33 ~ abs[`(total,660)`]~ '('*Mm^-1*')')) +
theme(legend.position="")+
stat_poly_eq(formula = y ~ x,
aes(label = paste({
eq <- ..eq.label..
eq_split <- strsplit(eq, "~`=`~")[[1]]
eq_rhs_split <- strsplit(eq_split[2], "(\\+|\\-)")[[1]]
sign <- stringr::str_extract(eq_split[2], "(\\+|\\-)")
new_eq <- paste(eq_split[1], # "italic(y)"
"~`=`~",
eq_rhs_split[2], # slope (e.g., "1.70*~italic(x)")
sign,
eq_rhs_split[1], collapse = "")
new_eq
}, ..rr.label.., sep = "*`,`~")),
parse = TRUE, label.x.npc = "left", vstep = 0.07, size=4.5)
How can I use the same code but with York regression, replacing the linear regression with York regression? Additionally, I’d like to automatically display the York regression equation, similar to how the stat_poly_eq
function provides the equation directly on the plot (without manual input).
Any information on this would be greatly appreciated.
the data can be found here
https://www.dropbox.com/scl/fi/qdj3j3s33khgk8kkfyf3u/MAAP_AE33_660_hourly.txt?rlkey=ez09v39uvuxvo1cs6uzqanri0&st=mumib0bi&dl=0