2016-11-15 32 views
3

我繪製與barplot()的曲線圖,並使用beside=TRUE參數的任何企圖似乎要返回的Error in -0.01 * height : non-numeric argument to binary operatorR錯誤= true參數

以下的誤差是圖中的代碼:

combi <- as.matrix(combine) 

barplot(combi, main="Top 5 hospitals in California", 
ylab="Mortality/Admission Rates", col = heat.colors(5), las=1) 

圖表的輸出是條形碼堆疊在一起而不是彼此相鄰。

enter image description here

enter image description here

+0

奇怪,這個錯誤應該只有當'COMBI發生'不是矩陣,qv這裏:http://stackoverflow.com/questions/14909665/barplot-not-working –

+0

@TimBiegeleisen我試圖改變組合使用t()但它不工作,只要我添加旁邊= TRUE參數 –

+0

你能向我們展示你的數據集'combine'? –

回答

3

的問題是不可複製的,當combine是一個data.frame:

combine <- data.frame(
    HeartAttack = c(13.4,12.3,16,13,15.2), 
    HeartFailure = c(11.1,7.3,10.7,8.9,10.8), 
    Pneumonia = c(11.8,6.8,10,9.9,9.5), 
    HeartAttack2 = c(18.3,19.3,21.8,21.6,17.3), 
    HeartFailure2 = c(24,23.3,24.2,23.8,24.6), 
    Pneumonia2 = c(17.4,19,17,18.4,18.2) 
) 

combi <- as.matrix(combine) 

barplot(combi, main="Top 5 hospitals in California", 
    ylab="Mortality/Admission Rates", col = heat.colors(5), las=1, beside = TRUE) 

enter image description here

+0

如果我不得不添加圖例,可以減少圖例圖標和文本之間的空間嗎? –