Home > Back-end >  adding labels and legend in graph_model function, reghelper package
adding labels and legend in graph_model function, reghelper package

Time:09-06

I would like to add a legend and labels to my graph created using a reghelper package.

This is the code:

dv1 = runif(n = 100, min = 1, max = 7)
dv2 = runif(n = 100, min = 1, max = 7)
dv3 = runif(n = 100, min = 1, max = 7)
country <- rep(c("India", "US", "Poland"), length.out = 100)
df <- data.frame(country, dv1, dv2, dv3)
library(reghelper)

dv1 <- as.numeric(dv1)
dv2 <- as.numeric(dv2)
dv3 <- as.numeric(dv3)
country <- as.factor(country)

lm0 <- lm(dv1 ~ dv2 * dv3   country, data = df, na.action = na.exclude)
summary(lm0)
graph_model(lm0, y=dv1, x=dv2, lines=country, split=dv3)

What should I add to the code to add a title, x and y labels, and legend labels? Thank you in advance!

CodePudding user response:

graph_model() produces ggplot2 object, so you can manipulate it with usual ggplot2 functions.

For example:

library(ggplot2)

p <- graph_model(lm0, y=dv1, x=dv2, lines=country, split=dv3)   
  labs(x='Nowy X', y='Nowy Y', title='Tytulik') 

update_labels(p, list(colour="Legenda"))
  • Related