2012-11-20 27 views
1

我嘗試使用矩陣中兩列的值將95%CI(下/上)添加到現有圖中時出現問題。使用這些信息添加錯誤欄的最佳方法是什麼?使用列中的值向現有圖添加誤差線

這裏是我的數據樣本:

option<-read.table(text=" 
distance p.move id option mean lower95%CI upper95%CI 
1  close 0.05 1 10% 13.682  11.306  15.768 
2  close 0.10 2 10% 10.886  9.336  12.270 
3  close 0.15 3 10% 8.402  7.262  9.580 
4  close 0.20 4 10% 7.240  6.132  8.350 
5  close 0.25 5 10% 6.322  5.288  7.370 
6  close 0.30 6 10% 5.850  4.920  6.714 
7  close 0.35 7 10% 3.838  3.084  4.648 
8  close 0.40 8 10% 3.600  2.936  4.200 
9  close 0.45 9 10% 3.380  2.702  4.016 
10  close 0.50 10 10% 3.152  2.462  3.720 
11  close 0.55 11 10% 2.772  2.214  3.286 
12  close 0.60 12 10% 3.072  2.458  3.596 
13  close 0.65 13 10% 2.670  2.134  3.212 
14  close 0.70 14 10% 2.194  1.724  2.634 
15  close 0.75 15 10% 1.980  1.612  2.336 
16  close 0.80 16 10% 2.028  1.594  2.466 
17  close 0.85 17 10% 1.650  1.294  1.974 
18  close 0.90 18 10% 1.916  1.564  2.254",header=T) 

option 

這是我的陰謀:

plot(option$mean~option$p.move,xlim=c(0,1),type="o",ylim=c(0,20), 
xlab="Probability",ylab="% time",col=1,lwd=1.85) 

非常感謝提前,

+0

如果你只是想另外繪製那些額外的列與您繪製'option $ mean'的方式相同,請參閱'?lines',它以'plot'相同的方式繪製線條,但是繪製現有繪圖。 –

回答

3

你可以添加e與lines相似的xtra列與plot相似,但是利用了現有的圖。 (見?lines?points)。

此外,當您plot一個數據幀,你可以跳過所有option$餵養optiondat參數(見?plot):

# draw original plot 
plot(mean ~ p.move, dat=option, xlim=c(0,1), type="o", ylim=c(0,20), 
    xlab="Probability",ylab="% time",col=1,lwd=1.85) 

# draw extra lines (the '%' in the column names gets converted to '.' by R) 
# note you can put your usual `plot` arguments into `lines` like lwd, type etc 
# if you want 
lines(upper95.CI ~ p.move, option) 
lines(lower95.CI ~ p.move, option) 

enter image description here

+0

非常感謝。我正在尋找實際的誤差線,但這看起來也不錯, – user1626688

+0

哦,好的。你的意思是從每個點延伸的垂直線?置信區間通常繪製爲線,而誤差線通常繪製爲垂直線。你可以使用'lines'並自己繪製垂直線。每個「x」座標是「p.move」,「y」座標從「lower95.CI」變爲「upper95.CI」。 –

+0

'plotrix'包中的'plotCI'('gplots'包中有一個版本)是一種可能性:請參閱http://rwiki.sciviews.org/doku.php?id=tips:graphics-base:errbars –

相關問題