Kode.Error404 Kode.Error404 - 25 days ago 6
R Question

R Error when using beside=TRUE parameter

I am plotting a graph with

barplot()
and any attempts to use the
beside=TRUE
parameter seem to return the error of
Error in -0.01 * height : non-numeric argument to binary operator


The following is the code for the graph:

combi <- as.matrix(combine)

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


The output of the graph is that the bars are stacked on each other instead of being beside each other.

enter image description here

enter image description here

J_F J_F
Answer

The issue is not reproducible, when combineis a 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