[R] How to adjust the regression script R/Rstudio?

Fabiano França f@bi@no@fr@nc@d@ @ending from hotm@il@com
Sun Sep 23 06:26:06 CEST 2018


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



-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: IVCM.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20180923/f8e28835/attachment.txt>


More information about the R-help mailing list