strengejacke / sjPlot

sjPlot - Data Visualization for Statistics in Social Science
https://strengejacke.github.io/sjPlot
603 stars 91 forks source link

sjPlot plot_model not displaying interaction names #888

Closed eimichae85 closed 1 year ago

eimichae85 commented 1 year ago

Hi there,

I am running a generalised linear mixed model with a lot of factors and their interactions. mod1<-glmer(cbind(branch_miner_Yes,branch_miner_No)~ Drought+Stratum+Year+Drought:Stratum+Drought:Year+Stratum:Year+(1|Tree.ID)+(1|Sample.ID), data=Herb1920, family=binomial(),na.action = na.exclude)

I want to visualise the model estimations with a forest plot. Using the following code: `Eplot_Miner<-plot_model(mod1, vline.color = "gray", colors = c("black","black"),sort.est=F,show.values = TRUE, value.offset = .45,value.size = 6,title = "", dot.size=5.3, line.size =0.8 ,transform = NULL,order.terms = c(1,3, 2, 5,4,6))+ theme_classic()+ theme(axis.text=element_text(face="bold",size=18), axis.title = element_text(color="black",face="bold",size=19), axis.line = element_line(colour = 'black', size = 1), axis.ticks = element_line(colour = "black", size = 1), legend.text=element_text(size=14), legend.title=element_text(size=15, face="bold"), plot.title = element_text(color="black", size=18, face="bold"))

Eplot_Miner`

However, for some reason plot_model won't show the interaction terms on the y axis, it just says "conditional" for all of them (see picture). Rplot

I realized that the problem only apperars witha glmer but not with a glmmTMB model.

strengejacke commented 1 year ago

Do you have a small dataset to reproduce this issue, or any other (fake) example that reproduces this issue?

eimichae85 commented 1 year ago

Yes. Here is the complete R-code (and at the very end I also provide the data as dput())

Herb1920<-read.csv("dummy_data.csv", header=T, sep=";")
str(Herb1920)

#Necessary packages
library(tibble)
library (glmmTMB)
library(lme4)
library(DHARMa)#check for Overdispersion
library(tidyr)
library(ggplot2)
library(car)
library(xlsx)
library(FSA)
library(cowplot)
library(rlang)
library(sjstats)
library(sjPlot)
library(sjlabelled)
library(sjmisc)
library(lme4)
library(lmerTest)
library(emmeans)
library(effects)
library(insight)
library(dplyr)
library(vegan)

str(Herb1920)
#Faktoren definieren
Herb1920$Year<-factor(Herb1920$Year)
#relevel(Herb1920$Year,ref="2019")
Herb1920$Drought <-as.factor(Herb1920$Drought)
#relevel(Herb1920$Drought,ref="0")
Herb1920$Stratum <-as.factor(Herb1920$Stratum)
levels(Herb1920$Stratum) <- list(lower  = "shade", upper = "sun")
#relevel(Herb1920$Stratum,ref="sun")
Herb1920$Tree.ID <-as.factor(Herb1920$Tree.ID)

mod<-glmer(cbind(branch_miner_Yes,branch_miner_No)~ Drought*Stratum+Drought*Year+Year*Stratum+(1|Tree.ID),
           data=Herb1920, family=binomial(),na.action = na.exclude)

Eplot_Miner<-plot_model(mod, vline.color = "gray",   colors = c("black","black"), sort.est=F,show.values = TRUE, value.offset = .45,value.size = 6,title = "",  dot.size=5.3, line.size =0.8 ,transform = NULL,order.terms = c(1,3, 2, 5,4,6))+
  theme_classic()+
  theme(axis.text=element_text(face="bold",size=18),
        axis.title = element_text(color="black",face="bold",size=19),
        axis.line = element_line(colour = 'black', size = 1),
        axis.ticks = element_line(colour = "black", size = 1),
        legend.text=element_text(size=14),
        legend.title=element_text(size=15, face="bold"),
        plot.title = element_text(color="black", size=18, face="bold"))

Eplot_Miner

DATA

Herb1920<-structure(list(Drought = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L ), levels = c("no", "yes"), class = "factor"), Tree.ID = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L, 12L, 12L, 13L, 13L, 14L, 14L, 15L, 15L, 16L, 16L, 17L, 17L, 18L, 18L, 19L, 19L, 20L, 20L, 21L, 21L, 22L, 22L, 23L, 23L, 24L, 24L, 25L, 25L, 26L, 26L, 27L, 27L, 28L, 28L, 29L, 29L, 30L, 30L, 31L, 31L, 32L, 32L, 33L, 33L, 34L, 34L, 35L, 35L, 36L, 36L, 37L, 37L, 38L, 38L, 39L, 39L, 40L, 40L, 41L, 41L, 42L, 42L, 43L, 43L, 44L, 44L, 45L, 45L, 46L, 46L, 47L, 47L, 48L, 48L, 1L, 1L, 2L, 2L, 3L, 3L, 10L, 10L, 11L, 11L, 12L, 12L, 13L, 13L, 14L, 14L, 15L, 15L, 16L, 16L, 17L, 17L, 18L, 18L, 19L, 19L, 21L, 21L, 22L, 22L, 23L, 23L, 24L, 24L, 25L, 25L, 26L, 26L, 27L, 27L, 28L, 28L, 29L, 29L, 30L, 30L, 31L, 31L, 32L, 32L, 33L, 33L, 37L, 37L, 38L, 38L, 39L, 39L, 43L, 43L, 44L, 44L, 45L, 45L, 46L, 46L, 47L, 47L, 48L, 48L), levels = c("102_6", "102_7", "102_8", "105_1", "105_2", "105_4", "111_7", "111_8", "111_9", "113_2", "113_4", "113_5", "114_7", "114_8", "114_9", "116_6", "116_7", "116_9", "122_3", "122_4", "122_5", "132_3", "132_4", "132_5", "242_2", "242_4", "242_5", "243_1", "243_2", "243_4", "245_1", "245_2", "245_5", "246_1", "246_2", "246_3", "251_10", "251_8", "251_9", "253_7", "253_8", "253_9", "254_6", "254_7", "254_8", "267_10", "267_6", "267_8"), class = "factor"), Stratum = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), levels = c("lower", "upper"), class = "factor"), Year = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), levels = c("1", "2"), class = "factor"), Treatment = c("Control", "Control", "Control", "Control", "Control", "Control", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Control", "Control", "Control", "Control", "Control", "Control", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Drought", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control", "Control" ), branch_miner_No = c(41L, 25L, 47L, 49L, 50L, 49L, 49L, 50L, 49L, 50L, 48L, 47L, 49L, 49L, 50L, 49L, 49L, 43L, 41L, 45L, 49L, 37L, 50L, 49L, 50L, 50L, 50L, 49L, 45L, 44L, 49L, 48L, 50L, 48L, 50L, 49L, 44L, 38L, 50L, 34L, 38L, 28L, 47L, 39L, 50L, 49L, 47L, 50L, 42L, 19L, 47L, 46L, 50L, 50L, 49L, 46L, 49L, 50L, 40L, 45L, 50L, 50L, 41L, 44L, 50L, 50L, 50L, 46L, 50L, 48L, 50L, 50L, 48L, 38L, 49L, 42L, 39L, 31L, 49L, 33L, 38L, 49L, 48L, 48L, 49L, 49L, 48L, 50L, 45L, 37L, 28L, 25L, 45L, 45L, 39L, 35L, 38L, 43L, 46L, 34L, 49L, 33L, 40L, 47L, 47L, 39L, 46L, 31L, 47L, 40L, 47L, 45L, 47L, 42L, 48L, 47L, 39L, 25L, 37L, 46L, 38L, 42L, 44L, 48L, 47L, 46L, 48L, 49L, 38L, 44L, 39L, 31L, 41L, 42L, 44L, 18L, 23L, 48L, 26L, 26L, 28L, 32L, 47L, 46L, 49L, 33L, 47L, 38L, 35L, 17L, 39L, 30L, 44L, 42L, 47L, 36L, 8L, 33L, 32L, 37L, 33L, 38L, 32L, 45L, 47L, 41L), branch_miner_Yes = c(9L, 25L, 3L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 2L, 3L, 1L, 1L, 0L, 1L, 1L, 7L, 9L, 5L, 1L, 13L, 0L, 1L, 0L, 0L, 0L, 1L, 5L, 6L, 1L, 2L, 0L, 2L, 0L, 1L, 6L, 12L, 0L, 16L, 12L, 22L, 3L, 11L, 0L, 1L, 3L, 0L, 8L, 31L, 3L, 4L, 0L, 0L, 1L, 4L, 1L, 0L, 10L, 5L, 0L, 0L, 9L, 6L, 0L, 0L, 0L, 4L, 0L, 2L, 0L, 0L, 2L, 12L, 1L, 8L, 11L, 19L, 1L, 17L, 12L, 1L, 2L, 2L, 1L, 1L, 2L, 0L, 5L, 13L, 22L, 25L, 5L, 5L, 11L, 15L, 12L, 7L, 4L, 16L, 1L, 17L, 10L, 3L, 3L, 11L, 4L, 19L, 3L, 10L, 3L, 5L, 3L, 8L, 2L, 3L, 11L, 25L, 13L, 4L, 12L, 8L, 6L, 2L, 3L, 4L, 2L, 1L, 12L, 6L, 11L, 19L, 9L, 8L, 6L, 32L, 27L, 2L, 24L, 24L, 22L, 18L, 3L, 4L, 1L, 17L, 3L, 12L, 15L, 33L, 11L, 20L, 6L, 8L, 3L, 14L, 42L, 17L, 18L, 13L, 17L, 12L, 18L, 5L, 3L, 9L)), row.names = c(NA, -166L), class = "data.frame")

eimichae85 commented 1 year ago

I streamlined the code a bit. any idea why the problem with the "conditional" labelling exists?

strengejacke commented 1 year ago

I have a guess, but let me look into this later. I'm currently preparing the CRAN submission of parameters, which is internally used by sjPlot, so I can resolve this issue once I submitted parameters.

strengejacke commented 1 year ago

Should be fixed in parameters:

library(parameters)
library(lme4)
library(sjPlot)
library(ggplot2)
load("d:/mail/test.RData")
Eplot_Miner <- plot_model(mod, vline.color = "gray", colors = c("black", "black"), sort.est = F, show.values = TRUE, value.offset = .45, value.size = 6, title = "", dot.size = 5.3, line.size = 0.8, transform = NULL, order.terms = c(1, 3, 2, 5, 4, 6)) +
  theme_classic() +
  theme(
    axis.text = element_text(face = "bold", size = 18),
    axis.title = element_text(color = "black", face = "bold", size = 19),
    axis.line = element_line(colour = "black", size = 1),
    axis.ticks = element_line(colour = "black", size = 1),
    legend.text = element_text(size = 14),
    legend.title = element_text(size = 15, face = "bold"),
    plot.title = element_text(color = "black", size = 18, face = "bold")
  )
Eplot_Miner

Created on 2023-03-31 with reprex v2.0.2

eimichae85 commented 1 year ago

Hi, thank you for working on this. Unfortunately I still have the same problem. I updated my R-version (4.2.3) and all my packages: e.g. sJPlot(2.8.13) , parameters (0.20.2) etc. Only two packages could not be updated: robustbase and cli but I guess that is not the problem.

I restarted R several times and only worked with the example that I provided here. Still I get the "conditional" labelling instead of the interaction names. What to do?

strengejacke commented 1 year ago

The fixes are on github only, but both packages will be updated on CRAN the next days. If you don't want to wait, try:

remotes::install_github("strengejacke/sjPlot")
remotes::install_github("easystats/parameters")
eimichae85 commented 1 year ago

Ah apparently I was not patient enough:) It works with the updated packages. Thanks a lot for fixing this issue so quickly!

eimichae85 commented 1 year ago

Sorry I have another follow-up isssue that may be related to the package update. I realized that the "vilne" ( "zero effect" line) is now much narrower now that it used to be. this is a problem because now 3/4 of my figures have a wide-zero effect line and 1/4 has a narrow line

(see exaples below):

wide narrow

For the love of my life I could not find a way to make this line wider. Is this somehow possible?

Thanks a lot!