Reputation: 245
I could not create barplot with following data frame
Age Male.Average Female.Average
---------------------------------------------------------
1: 0-19 Childhood 20.29543 18.14773
2: 20-39 Young Adult 22.35352 22.41548
3: 40-64 Mid Aged Adult 23.75663 23.64908
4: 65-84 Senior Age 21.45002 21.71446
5: 85+ Old Senior Age 21.72200 21.31565
I want to create grouped barplot like x= age, y= male.average, female.average in beside. It gives error:
Error in
barplot.default(d) : 'height' must be a vector or a matrix
Upvotes: 1
Views: 6451
Reputation: 886938
Assuming that we have a data.frame
barplot(`colnames<-`(t(df1[-1]), df1[,1]), beside=TRUE,
legend.text = TRUE, col = c("red", "green"),
args.legend = list(x = "topleft", bty = "n", inset=c(-0.05, 0)))
Upvotes: 2