Reputation: 84
Sorry if this is a double post, I've seen some similar posts but haven't found the exact solution I'm looking for.
I fit a glmer model to some reaction time data of the form:
m19 <- glmer(response ~ trial_z*stim + cond + (1 + stim | subj_idx),
na.action = na.exclude,
data = gng, family = "binomial",
control = glmerControl(optCtrl = list(maxfun = 50000)))
where: response
is binary (correct response, incorrect response) on a standard go/no-go task.
I want to plot odds ratios of the fixed effects using the sjplot::plot_model
function but don't seem to be able to get things looking quite right.
I want to plot these odds ratios for the fixed effects in my model:
library(broom.mixed)
tidy(m19,conf.int=TRUE,exponentiate=TRUE,effects="fixed")
which looks like:
# A tibble: 7 x 8
effect term estimate std.error statistic p.value conf.low conf.high
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 fixed (Intercept) 414. 123. 20.2 6.98e-91 231. 742.
2 fixed trial_z 0.697 0.0751 -3.35 7.97e- 4 0.564 0.860
3 fixed stimNoGo 0.00925 0.00257 -16.9 6.80e-64 0.00537 0.0159
4 fixed condThreeGo 1.48 0.151 3.82 1.32e- 4 1.21 1.80
5 fixed condFiveGo 1.69 0.174 5.07 4.08e- 7 1.38 2.06
6 fixed condSevenGo 1.51 0.151 4.07 4.73e- 5 1.24 1.83
7 fixed trial_z:stimNoGo 1.30 0.149 2.28 2.25e- 2 1.04 1.63
The following sjplot call produces the following plot object:
gg <- plot_model(m19, type="std", show.p=TRUE, ci.lvl=.95, dot.size=5,
line.size=2, vline.color = "black", axis.lim=c(.001, 2.25)) +
theme_bw(base_size=24) +
theme(panel.grid.major.y=element_blank()) +
ggtitle("") +
ylab("Odds Ratio")
plot(gg)
So I tried editing axis.limits within the call:
gg2 <- plot_model(m19, type="std", show.p=TRUE, ci.lvl=.95, dot.size=5,
line.size=2, vline.color = "black", axis.lim=c(.001, 11)) +
theme_bw(base_size=24) +
theme(panel.grid.major.y=element_blank()) +
ggtitle("") +
ylab("Odds Ratio")
plot(gg2)
Somewhat annoyingly, bumping the second concatenated axis.lim element to anything between 1 and 10 produced my attempt 1, but then anything above 10 sets that limit in the plot to 100 (not sure why this is...)
So I tried, based off other posts to edit the axes post-hoc:
gg + ylim(.001, 2.25)
My question:
I'd like a plot that is somewhat of a combination of attempt 2 and attempt 3.
In 2 I like that the scaling below and above 1 are different and that 1 (equal odds) has a special denotion that demonstrates that CIs that overlap with 1 represent a null effect. If I want than within plot_model()
's capabilities I am stuck at how I can get the axis to the right of that 1 mark to look more like the scale in attempt 3, which wipes out the nice delineation of odds for and against and sets the scale as uniform across all y values (also, this was certainly confusing at first, given that I'm looking to manage what the user sees on the x-axis. I assume there's a coord_flip
call somewhere in the function...).
If I can clarify further lmk. Thanks for your input!
Upvotes: 1
Views: 4560
Reputation: 7832
I think this might work:
gg + scale_y_log10(limits = c(0.001, 2.25))
Example:
library(sjPlot)
library(ggplot2)
model <- glm(vs ~ mpg + cyl, data = mtcars, family = "binomial")
p <- plot_model(model)
p + scale_y_log10(limits = c(0.001, 2.5))
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
Created on 2020-06-27 by the reprex package (v0.3.0)
Upvotes: 1