简体   繁体   中英

Is it possible to use sjplot::plot_model() to plot confidence interval along y-axis?

I would like to plot vertical confidence interval graph instead of horizontal confidence intervals graph.

Something like this:

在此处输入图像描述

from Statistics Globe Newsletter .

To answer your question, yes it is possible. Here is the data taken from the vi.nette example .

# prepare data
library(sjmisc)
data(efc)
efc <- to_factor(efc, c161sex, e42dep, c172code)
m <- lm(neg_c_7 ~ pos_v_4 + c12hour + e42dep + c172code, data = efc)

# simple forest plot
plot_model(m)

To create rotated errorbars, you need to apply coord_fixed first as coord_flip was already applied based on the source code . Then you can rotate the x axis text to make them readable.

p+coord_fixed() + 
  theme(axis.text.x = element_text(angle = 90))

在此处输入图像描述

To have the bars appear on the whiskers, you may need to draw over the default error bars as the width have been hard-coded.

p+coord_fixed() + 
  theme(axis.text.x = element_text(angle = 90)) + 
  geom_errorbar(
    aes_string(ymin = "conf.low", ymax = "conf.high"),
    width = 0.25
  )

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM