2012-12-08 42 views
3

我需要重現與附加圖像相似的圖形。我希望使用圖形比較置信區間的比例差異。如何使用R生成附加圖形?任何指針正確的方向將不勝感激。如何重現置信區間圖?

enter image description here

+1

這個問題似乎有點太模糊。你想用*定量數據*做些什麼?否則,你在尋找'?箭頭','?rect',...?或'?confint'?或''binom.test'? –

+1

如果您嘗試過這一點,並且一路遇到特定問題,那麼問題會更好。 – joran

+1

@Aaron:我認爲你會發現,精力充沛的答案「期望你在R代碼中提供一個數據集,然後試圖將你從擺脫折磨R noob的流水中拯救出來,我們中的許多人都認爲你所有的爲你的項目要求太高。 –

回答

7

沒有背景和重複的例子,它是很難給出一個很好的答案。但我認爲情節很有趣。

這裏我的嘗試與ggplot2。我仍然有alpha層的問題,但情節的主要思想是在這裏。

一些數據

structure(list(scen = 1:6, 
       name = c("I", "II", "III", "IV", "V","VI"), 
       ymin = c(0.06, -0.102, 0.487, 0.116, -0.436, 0.021), 
       ymax = c(-0.231,0.135, 0.117, 0.338, -0.347, -0.025)), 
      .Names = c("scen", "name", "ymin", "ymax"), 
      row.names = c(NA, 6L), 
      class = "data.frame") 

的數據是這樣的

DAT

scen name ymin ymax y 
1 1 I 0.060 -0.231 I 
2 2 II -0.102 0.135 II 
3 3 III 0.487 0.117 III 
4 4 IV 0.116 0.338 IV 
5 5 V -0.436 -0.347 V 
6 6 VI 0.021 -0.025 VI 

這是結果

enter image description here

theme_new <- theme_set(theme_bw()) 
p <- ggplot(data=dat) + 
    geom_segment(aes(x=ymin,y=scen,xend=ymax,yend=scen), 
       arrow=arrow(length=unit(0.3,"cm"), 
          ends='both'),size=1) 

p <- p+ geom_rect(xmin=max(dat$ymin)/2, 
        xmax=min(dat$ymax)/2, 
        ymin=0, 
        ymax=max(dat$scen)+1, 
        alpha=0.2,fill='grey') 

p <- p + geom_text(aes(x=(ymin+ymax)/2, 
         y=scen+0.2,label =name),size=6) 

p<- p + coord_cartesian(ylim=c(0,max(dat$scen)+3))+ 
    xlab(expression(P[1]-P[0]))+ 
    theme( 
    axis.ticks = element_blank(), 
    axis.text.y = element_blank(), 
    axis.text.x = element_blank(), 
    axis.title.x = element_text(face="bold", size=20)) 

p <- p + geom_vline(linetype ='dashed', 
        xintercept = mid.dash) 

p <- p + geom_text(aes(x= mid.dash, 
         y = max(dat$scen)+2, 
         label="Zone of Indifference", 
         color="NA*"),rotate=180) 
p <- p + theme(legend.position = "none") 

p

+1

'[po]' etc「需要在引號之外,例如'」hi「,beta [0],」bye「'如果這有助於OP –

+0

@ user1317221_G謝謝,我更新了答案 – agstudy

+1

@agstudy這個答案超出了 - 謝謝你肯定可以用我自己的數據集使用這個方法 – Borealis