2013-09-23 44 views
0

大家好,特別是所有R程序員,我都需要你的幫助。我正在嘗試使std錯誤欄散點圖![enter image description here] [1]但我無法管理它。到現在爲止,我可以製作帶有標籤和45度角線的散點圖(我也需要)。如果有人幫助我,或者在我現有的代碼中添加一些對我非常有用的代碼。散點圖與std錯誤

我的代碼

Dataset <- read.table("AvgDis.csv",header=TRUE, sep="", 
         na.strings="NA", dec=".", 
         strip.white=TRUE) 

plot(Dataset$True,Dataset$False, 
    xlim=c(0,100), ylim=c(0,100), 
    main="Average % of disorder", 
    xlab="True", ylab="False", 
    pch=19,col= "blue") 

text(Dataset$True,Dataset$False, 
    labels=Dataset$MotifId, 
    cex= 0.7, pos=3) 

abline(0,1) 

數據,我使用:

False  True  MotifId 
54.1666675 33.33333 aps 
35.2040825 48.57143 dbox 
44.3055575 94.44444 ken 
70.37037  60   mdm2 
1.6666675  0   met 
72.222225 100   ptk 
46.9212975 68.51852 scftrcp1 
55.5555575 70.83333 siah 
+0

std錯誤是什麼? – dayne

+0

您試圖輸入圖像,但不知何故被刪除。平均值(x)或平均值(y)或相關係數或迴歸線的CI可能存在偏差,但您尚未說明偏差。 –

回答

2

首先,我要創建一個假的數據幀,因爲你已經張貼你的數據使得不方便複製和粘貼。

# Make a fake dataset since it is inconvenient to copy & paste the data you show 
set.seed(13) 
False <- rnorm(10, mean=50, sd=10) 
True <- rnorm(10, mean=50, sd=10) 
MotifId <- letters[1:10] 
Dataset <- data.frame(False, True, MotifId) 

您需要以某種方式計算標準錯誤。讓我們想象一下,所有的數據點都具有相同的標準誤差:

Dataset$stderr <- 7 # This will recycle to the number of rows of Dataset 

現在創建您的情節,並添加誤差線爲arrow S,所建議的here

plot(Dataset$True,Dataset$False, 
    xlim=c(0,100), ylim=c(0,100), 
    main="Average % of disorder", 
    xlab="True", ylab="False", 
    pch=19,col= "blue") 
text(Dataset$True,Dataset$False, 
    labels=Dataset$MotifId, 
    cex= 0.7, pos=3) 
abline(0,1) 
arrows(x0=Dataset$True, y0=Dataset$False - Dataset$stderr, 
     x1=Dataset$True, y1=Dataset$False + Dataset$stderr, 
     angle=90, code=3, length=0.05) 

enter image description here

在長期來看,我認爲最好是使用ggplot2數據可視化包

require(ggplot2) 
# Build the plot from layers 
p <- ggplot(Dataset, aes(x=True, y=False, label=MotifId)) + 
     geom_point() + 
     geom_text(, vjust=1, hjust=1) + 
     geom_errorbar(aes(ymin=False-stderr, ymax=False+stderr), width=1) + 
     geom_abline(slope=1, intercept=0) + 
     xlim(c(0, 100)) + 
     ylim(c(0, 100)) + 
     ggtitle("Average % of disorder") + 
     theme_bw() 
print(p) 

enter image description here

+0

感謝您的善意幫助:) – Paul85