How to adjust the regression script R/Rstudio?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to adjust the regression script R/Rstudio?

fa_bianofs
Dear, how to set up the equation of the straight line and the R ^ 2, remove the bars of the chart area and the caption to the right?

Follow the attached file containing the data. We used the R version 3.4.4.

library(plotly)
library(ggplot2)


setwd("C:\\Users\\Fabiano\\Desktop\\Artigo OE")
dados <- read.table('IVCM.txt', header =T)

lm_labels <- function(dados) {
  mod <- lm(IVCM ~ Doses, data=dados)
  formula <- sprintf("italic(y) == %.2f %+.2f * italic(x)",
                     round(coef(mod)[1], 2), round(coef(mod)[2], 2))

  r <- cor(dados$Doses, dados$IVCM)
  r2 <- sprintf("italic(R^2) == %.2f", r^2)
  data.frame(formula=formula, r2=r2, stringsAsFactors=FALSE)
}

library(plyr) # For the ddply() function
labels <- ddply(dados, "Fungicidas", lm_labels)
labels

f_labels <- data.frame(Fungicidas = c("Água", "Frowncide", "Cravo", "Canela", "Capim-Limão", "Tomilho"), label = c("H2O", "F500SC", "cv", "Can", "CL", "Tom"))

p <- ggplot(dados, aes(x=Doses, y=IVCM, add = "reg.line", conf.int = TRUE, parse = TRUE)) +
  geom_point(size = .5) +
  facet_wrap(~ Fungicidas) +
  stat_smooth(aes(colour = Fungicidas), add = "loess", method = "lm", formula = y ~ x) +
  geom_text(x=0.6, y=9.5, size = 3, aes(label=formula), data=labels, parse=TRUE, hjust=0) +
  geom_text(x=0.6, y=9, size = 3, aes(label=r2), data=labels, parse=TRUE, hjust=0) +
  theme_bw()



(p=ggplotly(p))

Best regards,

Fabiano França da Silva
Doutorando em Fitotecnia - ESALQ/USP
MSc Fitotecnia - UFLA
Engº. Agrônomo - UFLA
(35) 9 9155-5443 TIM



______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

IVCM.txt (2K) Download Attachment