2012-02-27 17 views
5

我正在使用latticeDotplot()使用Hmisc繪製dotplot()。當我使用默認參數,我可以繪製誤差棒不小的垂直結局在dotplot中繪製錯誤條線的垂直末端

--O -

,但我想獲得

| - O-- |

我知道我能得到

| --O - |

當我使用從 latticeExtra plotrixsegplot() centipede.plot(),但是這些解決方案不給我這麼好的調理選項爲 Dotplot()

。我試圖用plot.line,這對於改變錯誤條線的顏色,寬度等效果很好par.settings玩,但到目前爲止,我一直不成功加入垂直結局:

require(Hmisc) 
mean = c(1:5) 
lo = mean-0.2 
up = mean+0.2 
d = data.frame (name = c("a","b","c","d","e"), mean, lo, up) 
Dotplot(name ~ Cbind(mean,lo,up),data=d,ylab="",xlab="",col=1,cex=1, 
     par.settings = list(plot.line=list(col=1), 
         layout.heights=list(bottom.padding=20,top.padding=20))) 

enter image description here

請不要給我使用ggplot2的解決方案...

+0

的一個起點可以是使用'bwplot'和修改面板,即'panel.bwplot'。 – Andrie 2012-02-27 16:31:28

+0

以下線程可能會有所幫助。 http://r.789695.n4.nabble.com/dotplots-with-error-bars-td4382474.html http://tolstoy.newcastle.edu.au/R/e2/help/06/10/2791.html – 2012-02-27 17:06:06

回答

6

我在過去有同樣的需求,barchart()而不是Dotplot()

我的解決方案是創建一個自定義的面板功能:(1)首先執行原始面板功能; (2)然後使用panel.arrows()添加誤差條(使用雙頭箭頭,其中頭部的邊緣與軸形成90度角)。

下面是可能會是什麼樣Dotplot()

# Create the customized panel function 
mypanel.Dotplot <- function(x, y, ...) { 
    panel.Dotplot(x,y,...) 
     tips <- attr(x, "other") 
     panel.arrows(x0 = tips[,1], y0 = y, 
        x1 = tips[,2], y1 = y, 
        length = 0.15, unit = "native", 
        angle = 90, code = 3) 
} 

# Use almost the same call as before, replacing the default panel function 
# with your customized function. 
Dotplot(name ~ Cbind(mean,lo,up),data=d,ylab="",xlab="",col=1,cex=1, 
     panel = mypanel.Dotplot, 
     par.settings = list(plot.line=list(col=1), 
         layout.heights=list(bottom.padding=20,top.padding=20))) 

enter image description here

+0

不錯的一個!我認爲這些面板功能可以做到魔術,但是格子手冊並不簡單,並且可以採取很多方法來改變參數。隊友的歡呼聲! – 2012-02-27 18:25:54

+0

嗯現在我有問題,因爲它不工作時,我應用兩個更多的條件。通過添加另外兩個條件來看到:'Dotplot(name〜Cbind(mean,lo,up)| condX * condY,...)'。有任何想法嗎? – 2012-02-28 16:54:49

+0

@GeekOnAcid - 我現在沒時間了。我建議你在自定義的面板函數裏放一行'browser()'(第一行可以)。然後,當/調用該面板函數時,它會中斷執行,並且可以在那裏查看,例如,看看「tips < - attr(x,」other「)是否仍然提取正確的數據。 (如果你正在使用'groups ='而不是通過調節(通過'|'),我會說你可能需要處理整個面板。重疊()'morass,但我相信*這可能不是問題。 – 2012-02-28 17:20:54