label on Y axis, sjPlot. exponential / integer?

Today my nice graph that previously showed percentages between 1% and 100% on Y axis, suddenly jumped to being in exponential form, making it very hard to interpret.

what happened?

I'm using sjPlot. Very simple command shown below, including picture of the problem. Is there some "accuracy" command I can adjust to get this back to normal integers on Y axis (i.e., the top should read "41%" instead of "4x+01%" )

sjPlot relies on ggplot2 according to this page.

My simple commands using sjPlots "plot" command:

DIST <- ggpredict(me.model.glm, terms = c("DIST"))
DIST
plot(DIST, connect.lines = TRUE)

Hello,

Can you generate a reprex of this example so we can run it ourselves and check what's going on? A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here:

PJ

I can recreate this if I change scipen to negative. perhaps set scipen to positive

options(scipen = -999)
> 40
[1] 4e+01

Hey @nirgrahamuk and @pieterjanvc thanks for input. Here are two responses.

(1) see reprex below.

(2) could you be a bit more specific about WHERE to use this options(scipen)?
I tried this but R returned "NULL". But perhaps I'm stupid, I dont know what this scipen means?

Thx, Scott


  suppressPackageStartupMessages({
    library(sjPlot)
    library(ggeffects)})
  
  # create ex. data set.  1 row per respondent (dataset shows 2 resp). 
  cedata.1 <- data.frame( id    =  c(1,1,1,1,1,1,2,2,2,2,2,2),    
                          QES    = c(1,1,2,2,3,3,1,1,2,2,3,3),   # Choice set   
                          Alt    = c(1,2,1,2,1,2,1,2,1,2,1,2),   # Alt 1 or Alt 2 in  choice set 
                          LOC    = c(0,0,1,1,0,1,0,1,1,0,0,1),   # attribute. binary categorical variable
                          SIZE   = c(1,1,1,0,0,1,0,0,1,1,0,1),   # attribute. binary categorical variable
                          Choice = c(0,1,1,0,1,0,0,1,0,1,0,1),   # if  Chosen (1) or not (0)
                          gender = c(1,1,1,1,1,1,0,0,0,0,0,0)   
  )
  
  # convert to factor as required by sjPlot
  cedata.1$Choice <- as.factor(cedata.1$Choice)
  cedata.1$LOC <- as.factor(cedata.1$LOC)
  cedata.1$SIZE <- as.factor(cedata.1$SIZE)
  
  # estimate model
glm.model <- glm(Choice ~  LOC*SIZE, data=cedata.1, family = binomial(link = "logit"))

  # estimate change in Pred Prob for the Interaction
LOC.SIZE <- ggpredict(glm.model, terms = c("LOC", "SIZE")) 
LOC.SIZE
#> 
#> # Predicted probabilities of Choice
#> # x = LOC
#> 
#> # SIZE = 0
#> 
#> x | Predicted |   SE |       95% CI
#> -----------------------------------
#> 0 |      0.33 | 1.22 | [0.04, 0.85]
#> 1 |      0.50 | 1.41 | [0.06, 0.94]
#> 
#> # SIZE = 1
#> 
#> x | Predicted |   SE |       95% CI
#> -----------------------------------
#> 0 |      0.67 | 1.22 | [0.15, 0.96]
#> 1 |      0.50 | 1.00 | [0.12, 0.88]
#> Standard errors are on the link-scale (untransformed).

  # plot interaction
  plot(LOC.SIZE, connect.lines = TRUE)

plot(COMP.DIST) + options(scipen = 999)

In general options scipen is used before the statement that produces printed values that you want to control. And its a standalone statement to your R session so shouldn't be plussed with anything.

thx. I tried messing around with different placements for the "options(scipen = 999)" command, but didn't seem to make any difference. Is it possible you could enter it into the reprex above so i can see how you might use it?
Thx
Scott

ok, the scipen thing is a red herring.
You can change the y formatting like so

plot(LOC.SIZE, connect.lines = TRUE)  + 
  ggplot2::scale_y_continuous(labels = function(x) insight::format_value(x,
                                                               as_percent=TRUE,
                                                               digits=2))

Fantastic, that fixed it, thanks.

A minor detail: I prefer with no digits after the decimal, i.e., 40% instead of 40.00%. I tried messing with "digits=2" but couldn't get it to round to nearest. Tips?

plot(LOC.SIZE, connect.lines = TRUE)  + 
  ggplot2::scale_y_continuous(labels = function(x) paste0(round(100*x),"%"))

fantastic, thanks much.
Any chance you can give input on my question about R packages that test for equality of marginal effects (both first/second differences?) Equality of marginal effects (first / second differences)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.