‘height’ must be a vector or a matrix. barplot error

You can specify the two variables you want to plot rather than passing the whole data frame, like so:

data <- structure(list(V1 = c(34.88372093, 35.07751938, 35.27131783, 35.46511628, 35.65891473, 35.85271318), 
                       V2 = c(0.00029997, 0.00019998, 0.00029997, 0.00029997, 0.00069993, 0.00069993)), 
                  .Names = c("V1", "V2"), row.names = c(NA, 6L), class = "data.frame")

barplot(data$V2, data$V1, xlab="Percentage", ylab="Proportion")

Alternatively, you can use ggplot to do this:

library(ggplot2)
ggplot(data, aes(x=V1, y=V2)) + geom_bar(stat="identity") + 
  labs(x="Percentage", y="Proportion")

Leave a Comment