It is a follow-up question. When I run the code given below, I get warning message that I think is due to no facets requirement in my code while the source code mentioned in link included facets. Have a look and please let me know which part needs to be amended. Looking forward!
Code:
library(dplyr) library(ggplot2) library(ggpmisc) df <- diamonds %>% dplyr::filter(cut%in%c("Fair","Ideal")) %>% dplyr::filter(clarity%in%c("I1" , "SI2" , "SI1" , "VS2" , "VS1", "VVS2")) %>% dplyr::mutate(new_price = ifelse(cut == "Fair", price* 0.5, price * 1.1)) p <- ggplot(df, aes(x,y, color=factor(cut))) p <- p + stat_smooth(method = "lm", formula = y ~ x-1, size = 1, level=0.95) p <- p + geom_point(alpha = 0.3) p <- p + stat_poly_eq(aes(label = paste(..rr.label..)), label.x.npc = "right", label.y.npc = 0.15, formula = formula, parse = TRUE, size = 3) + stat_fit_glance(method = 'lm', method.args = list(formula = formula), geom = 'text', aes(label = paste("P-value = ", signif(..p.value.., digits = 4), sep = "")),label.x.npc = 'right', label.y.npc = 0.35, size = 3) print(p)
Warning messages:
1: Computation failed in stat_poly_eq()
: object of type 'closure' is not subsettable
2: Computation failed in stat_fit_glance()
: object of type 'closure' is not subsettable