Eri*_*ail 0 plot visualization r ggplot2 sjplot
我正在使用sjplot https://strengejacke.github.io/sjPlot/并享受可视化和比较如下估计的可能性(参见下面的工作示例)。我想知道是否有可能在r,可能的 n ggplot2 中,仅根据估计值和标准误差绘制结果?假设我在一篇论文中看到一个模型,我估计了我自己的模型,现在我想将我的模型与论文中的模型进行比较,其中我只有估计值和标准误差。我在SO上看到了这个,但也有点基于模型。
任何反馈或建议将不胜感激。
# install.packages(c("sjmisc","sjPlot"), dependencies = TRUE)
# 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
library(sjPlot)
plot_model(m)
Run Code Online (Sandbox Code Playgroud)
我想一个暂时的期望结果看起来有点像这样,
我刚刚遇到coefplot https://cran.r-project.org/web/packages/coefplot/但我在一台没有 R 的机器上,我知道,奇怪,但我会尽快研究coefplot。也许这是一条可能的路线。
您可以使用该dotwhisker
软件包轻松完成此操作。默认情况下,该包将 95% 的 CI 显示为须线,但您可以修改您作为输入输入的数据框以进行更改。
# Package preload
library(dotwhisker)
library(broom)
library(dplyr)
# run a regression compatible with tidy
m1 <- lm(mpg ~ wt + cyl + disp + gear, data = mtcars)
# regression compatible with tidy
m1_df <- broom::tidy(x = m1) # create data.frame of regression results
m1_df # a tidy data.frame available for dwplot
#> # A tibble: 5 x 5
#> term estimate std.error statistic p.value
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 (Intercept) 43.5 4.86 8.96 0.00000000142
#> 2 wt -3.79 1.08 -3.51 0.00161
#> 3 cyl -1.78 0.614 -2.91 0.00722
#> 4 disp 0.00694 0.0120 0.578 0.568
#> 5 gear -0.490 0.790 -0.621 0.540
# create new columns for upper and lower bounds
m1_df <- m1_df %>%
dplyr::mutate(
.data = .,
conf.low = estimate - std.error,
conf.high = estimate + std.error
)
# creating the dot and whisker plot
# note that whiskers correspond to standard error and not 95% CI
dotwhisker::dw_plot(m1_df)
Run Code Online (Sandbox Code Playgroud)
您还可以查看小插图中的示例,这些示例展示了如何修改此基本图,尤其是当您想比较不同模型的结果时:https : //cran.r-project.org/web/packages/dotwhisker/vignettes/kl2007_examples .html