2014-03-19 90 views
2

我有它看起來像這樣一個原始數據: Àbçdéfghījklmñøp 1 15.0 20 23.3 26.5 28 29.0 31.8 32.0 32.0 33.8 36.0 38 40 46 47.0 55.0 2 10.0 13 16.0 20.0 10 19.5 14.0 15.0 31.0 15.0 24.6 29 31 46 26.7 38.2 3 18.0 25 29.5 45.0 47 36.5 41.0 38.0 34.5 63.0 43.0 41 42 55 55.0 78.0 4 32.5 60 108.7 88.0 83 65.9 84.9 125.1 62.6 83.0 71.6 53 55 72 88.3 123.8 5 22.0 36 65.0 63.0 60 43.8 53.0 74.0 44.3 71.0 50.3 44 46 62 63.5 96.0 6 10.0 NA NA NA 30 NA NA NA NA 20.0 NA NA NA NA NA NA 7 15.0 NA NA NA 25 NA NA NA NA NA NA NA NA NA NA NA 8 5.0 NA NA NA NA NA 40 30.0 NA NA NA NA NA NA NA NA多個彩色框圖與圖例

這些實際上是2.5,25,50,75和97.5%的值。我想創建這些每個不同顏色的方塊圖,然後標記中間點與箱線圖的一個點。我試着寫了下面的命令,但卡住了一個錯誤我無法理解。

Boxplot <- read.csv(file="Boxplots.csv",head=TRUE,sep=",") 
Boxplot 
attach(Boxplot) 
boxplot(Boxplot, las = 2, col = c("sienna","royalblue2","chartreuse3","chartreuse4","chocolate","chocolate1","chocolate2","chocolate3","chocolate4","coral","coral1","coral2","coral3","coral4","cornflowerblue"), 
     at = c(1,2,3,4,5, 6,7,8,9, 10,11,12,13,14,15), par(mar = c(0, 5, 4, 2) + 0.1), 
     names = c("","","","","","","","","","","","","","","")) 

請幫助。

回答

1

我(總是)避開attach。特別是在這裏,因爲你已經分配給Boxplot你的數據,所以它已經「附加」。你得到的錯誤可能是由於你的col參數比列數的長度越長。

> dat <- read.table(header = TRUE, text = "A  B  C  D  E  F  G 
    15.0 20.0 23.3 26.5 28.0 29.0 31.8 
    10.0 13.0 16.0 20.0 10.0 19.5 14.0 
    18.0 25.0 29.5 45.0 47.0 36.5 41.0 
    32.5 60.0 108.7 88.0 83.0 65.9 84.9 
    22.0 36.0 65.0 63.0 60.0 43.8 53.0") 

> boxplot(dat, col = rainbow(7), medlwd = 0) 
> points(sapply(dat, median), pch = 19) 

enter image description here

+0

非常感謝您,先生。每個這些列值的各種子類的組合。有沒有可能來標記的,比方說,2或在這些箱形圖這些類別的3位數點? – user3370708

+0

是的,也許。他們是在不同的數據幀? –

+0

是的,先生,對每個類別的子集的消失爲使每列,以便單獨提供(我指的是百分已採取了針對個別子爲好)。 – user3370708