standel
sex pollut or lcl ucl
0 patho. 1.74 1.52 1.98
0 spine 1.94 1.83 2.05
0 clavic 1.83 1.66 2.01
0 humerus 1.64 1.47 1.83
0 forearm 1.48 1.38 1.60
0 wrist 1.18 0.93 1.49
0 hand 1.39 1.31 1.47
0 HIP 1.84 1.70 1.99
0 tibia 1.71 1.59 1.84
0 foot 1.45 1.35 1.56
0 pelvis 2.74 2.33 3.22
1 patho. 1.82 1.47 2.26
1 spine 2.04 1.88 2.21
1 clavic 1.89 1.70 2.11
1 humerus 1.85 1.60 2.14
1 forearm 1.67 1.51 1.84
1 wrist 1.11 0.82 1.49
1 hand 1.45 1.35 1.55
1 HIP 2.03 1.84 2.23
1 tibia 1.73 1.58 1.90
上面是我要畫得DATA
datf=read.table(file.choose(),sep="\t",header=T)
datf <- datf[order(datf$pollut, datf$sex), ]
datfPlusNA <- lapply(split(datf, datf$pollut), function(x) rbind(NA, x, NA))
datf <- do.call(rbind, datfPlusNA) #在兩兩pollut資料中加入NA,可以在畫圖時明顯分隔出不同pollut的OR線
nr <- nrow(datf) # 總共有幾行,畫幾條線
with(datf, {# 用這個資料去畫圖
# 先劃出一張圖
plot(1:nr, or, ylim = c(0.6, 4.2), type = 'n', xaxt = 'n', xlab = 'fracture site', ylab = 'Odds Ratio and 95% CI', frame.plot = TRUE, panel.first = grid(nx = NA, ny = NULL))
arrows(1:nr, lcl, 1:nr, ucl, length = 0.02, angle = 90, code = 3, col = factor(sex))
# 使用arrows可以有線明顯標出區間的極大值和極小值
segments(1:nr, lcl, 1:nr, ucl, col = factor(sex)) #在畫出OR信賴區間的線
# 將OR點出來
points(1:nr, or, pch = 19, cex = 0.6)
xLabels <- na.omit(unique(pollut))
axis(1, seq(4, 64, by =11) - 0.5, xLabels)
})
abline(h = 1.0)
這是code但X軸畫不清,請大大幫忙謝謝