How do I describe a straight line equation of a glmm in an xy graph on R?

Asked

Viewed 357 times

1

Hello, I have data on age (X) and species richness per sample (y). I made a glmm and would like to know how to write the equation correctly in the figure in R. Someone has some site/paper to indicate?

Obg,

1 answer

5


There are several ways to include the equation in the figure, depending on how you are filling the graph. Here are some examples, if you want a more specific answer to your problem, please enter the code you created.

Using plot:

x<- runif(1000, min = 0, max=5)
y<- pi + x^2
plot(x, y, main= expression(Gráfico ~ da ~ Equação ~ pi + x^2))

Generates the figure: inserir a descrição da imagem aqui

Using ggplot:

library(ggplot2)
library(ggpmisc)
dados <- data.frame(x = c(1:100))
dados$y <- pi + dados$x^2 + rnorm(100, sd = 500)
minha.formula <- y ~ x
ggplot(data = dados, aes(x = x, y = y)) +
  geom_point()+
  geom_smooth(method = "glm", se=FALSE, color="blue", formula = minha.formula) +
  stat_poly_eq(formula = minha.formula,
               eq.with.lhs = "italic(hat(y))~`=`~",
               aes(label = paste(..eq.label.., ..rr.label.., ..AIC.label.., sep =  "*plain(\",\")~")), 
               parse = TRUE) +
  labs(title= expression(Gráfico ~ da ~ Equação: ~ pi +x^2))

Generates the figure:

inserir a descrição da imagem aqui

I hope I’ve helped :)

  • Hi Marina. Very good your tip.

  • hello, I really liked this solution, but I wonder if you have how to put the significance of the coefficients, I tried to locate where the function stat_poly_eq, withdrawing ..eq.label.. but I didn’t succeed, you would know if you have how to put?

  • Hi @Jeankarlos, stat_poly_eq compute x, y, eq.label, rr.label, adj.rr.label, AIC.label and BIC.label (see the documentation). There are other ways to put formula and other information on the graph. That post in the OS in English has an example with the inclusion of p-value.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.