2016-07-26 48 views
1

barplot我无法创建barplot与下面的数据帧如何创建从数据帧

    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 

我想创建分组barplot如x =年龄,Y = male.average,female.average在旁边。它提供了错误:

Error in barplot.default(d) : 'height' must be a vector or a matrix

回答

1

假设我们有一个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))) 

enter image description here