2015-03-02 115 views
-1

我想生成一個類似於this link的圖。但是,我想顯示每個均值的誤差線,我不知道如何在R中執行此操作。 我想將MeansG1和MeansG2繪製爲單獨的圖。我的數據:使用R中相同x軸和不同y軸的多個繪圖的繪圖方法和標準誤差

data<-structure(list(MeansG1=c(10.780877,8.675726,10.398065,11.617315,12.231693,8.292337,8.093416,10.744478,10.531539,11.459219,12.316292,11.272801), 
       STEG1=c(0.2578710,0.2569172,0.2502743,0.2558724,0.2523819,0.2427068,0.2507437,0.2475850,0.2421691,0.2365641,0.2350861,0.2312222), 
       MeansG2=c(11.780877,9.675726,11.398065,12.617315,13.231693,12.292337,12.093416,12.744478,12.531539,11.459219,12.316292,12.272801), 
       STEG2=c(0.2578710,0.2569172,0.2502743,0.2558724,0.2523819,0.2427068,0.2507437,0.2475850,0.2421691,0.2365641,0.2350861,0.2312222)), 
      .Names = c("MeansG1", "STEG1", "MeansG2", "STEG2"), row.names=1:12,class = "data.frame")  

謝謝。

+1

請嘗試。 – Khashaa 2015-03-02 11:53:12

+1

你嘗試了什麼?顯示你的代碼。 – 2015-03-02 12:03:49

+1

今天,該鏈接有4個圖表。你能否更具體一些? – jbaums 2015-03-02 12:49:32

回答

0

我更喜歡polygon()這類任務。下面是一個使用你的數據的例子。我希望它有幫助,並讓我知道是否有任何需要解釋。

# get the data ready 
g1 <- data.frame(mean = data$MeansG1, 
       up = data$MeansG1 + data$STEG1, 
       down = data$MeansG1 - data$STEG1) 
g2 <- data.frame(mean = data$MeansG2, 
       up = data$MeansG2 + data$STEG2, 
       down = data$MeansG2 - data$STEG2) 
plotData <- list(g1, g2) 

# setup the plotting region 
par(mfcol = c(2, 1)) 

### make the plots 
for(i in plotData){ 
    dd <- i 
    plot(dd$mean, type = "n", ylim = range(dd)) 
    xvals <- 1:dim(dd)[1] 
    polygon(c(xvals, rev(xvals)), c(dd$up, rev(dd$down)), col = "#ff000050", border = NA) 
    lines(dd$mean, col = "red") 
} 
相關問題