如何在R中创建比值比和95%CI图

Mes*_*eso 4 plot r

我估计了比值比,相应的95%CI的六种污染物超过4个滞后期.如何创建一个类似于R中附图的垂直图?下图是在SPSS中创建的.生成该图的示例数据如下:

lag pollut  or  lcl ucl
0   CO  0.97    0.90    1.06
0   PM10    1.00    0.91    1.09
0   NO  0.97    0.92    1.02
0   NO2 1.01    0.89    1.15
0   SO2 0.97    0.85    1.11
0   Ozone   1.00    0.87    1.15
1   CO  1.03    0.95    1.10
1   PM10    0.93    0.86    1.01
1   NO  1.01    0.97    1.06
1   NO2 1.08    0.97    1.20
1   SO2 0.94    0.84    1.04
1   Ozone   0.94    0.84    1.04
2   CO  1.09    1.02    1.16
2   PM10    1.04    0.96    1.13
2   NO  1.04    1.00    1.08
2   NO2 1.07    0.96    1.18
2   SO2 1.05    0.95    1.17
2   Ozone   0.93    0.84    1.03
3   CO  0.98    0.91    1.06
3   PM10    1.14    1.05    1.24
3   NO  0.99    0.95    1.04
3   NO2 1.01    0.91    1.12
3   SO2 1.11    1.00    1.23
3   Ozone   1.00    0.90    1.11
Run Code Online (Sandbox Code Playgroud)

在SPSS中创建的优势比和95%CI图

Mik*_*kko 9

您也可以使用ggplot2执行此操作.代码有点短:

 dat <- read.table("clipboard", header = T)
 dat$lag <- paste0("L", dat$lag)

 library(ggplot2)

 ggplot(dat, aes(x = pollut, y = or, ymin = lcl, ymax = ucl)) + geom_pointrange(aes(col = factor(lag)), position=position_dodge(width=0.30)) + 
 ylab("Odds ratio & 95% CI") + geom_hline(aes(yintercept = 1)) + scale_color_discrete(name = "Lag") + xlab("")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

编辑:这是一个更接近SPSS数字的版本:

ggplot(dat, aes(x = pollut, y = or, ymin = lcl, ymax = ucl)) + geom_linerange(aes(col = factor(lag)), position=position_dodge(width=0.30)) +
geom_point(aes(shape = factor(lag)), position=position_dodge(width=0.30)) + ylab("Odds ratio & 95% CI") + geom_hline(aes(yintercept = 1)) + xlab("")
Run Code Online (Sandbox Code Playgroud)

  • +1虽然我会使用`+ scale_y_log10()`因为它的优势比 (4认同)