2016-11-15 67 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

如果我不得不添加图例,可以减少图例图标和文本之间的空间吗? –