Brex Led
Brex Led

Reputation: 21

I would like to plot those graph from sjPlot::plot_model() in R on the same line

plot1<-plot_model(m3,type = "pred",terms = 
c("anno","dimensione_capoluogo","rip."),
colors = c("grey80","grey60","black"),
grid=T,  #T disegna in quadranti diversi, F fa multiline
ci.lvl = NA, # rumuove intervalli di confidenza
axis.title = c("anno","percentuale pop attiva"),
title="Stima longitudinale di popolazione attiva",
legend.title="dimensione\ncapoluogo",
grid.breaks=10)+
scale_x_continuous(breaks = seq(2001, 2023, by = 2)) + geom_line()
plot(plot1)

enter image description here

I didnt find any help, just how to set the grid of multiple graphs, but this is just one

Upvotes: 1

Views: 172

Answers (1)

jared_mamrot
jared_mamrot

Reputation: 26675

You can specify the number of rows using facet_wrap(), e.g.

library(ggplot2)
# install.packages("survey")
library(survey)
# install.packages("sjPlot")
library(sjPlot)

# load an in-built dataset
data(api)

# create a model to plot
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
model1 <- svyglm(api00~ell+meals+mobility, design=dstrat)

# plot the model
plot_model(model1, type = "pred", terms = c("meals", "mobility", "ell"), grid = TRUE)


# plot the data over two rows
plot_model(model1, type = "pred", terms = c("meals", "mobility", "ell"), grid = TRUE) +
  facet_wrap(~c("meals", "mobility", "ell"), nrow = 2)


# In your case, you would specify nrow = 1
plot_model(model1, type = "pred", terms = c("meals", "mobility", "ell"), grid = TRUE) +
  facet_wrap(~c("meals", "mobility", "ell"), nrow = 1)

Created on 2023-07-28 with reprex v2.0.2

Upvotes: 1

Related Questions