如何从数据框创建条形图 [英] How to create barplot from dataframe
本文介绍了如何从数据框创建条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法使用以下数据框创建条形图
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
我想在旁边创建分组的条形图,例如x =年龄,y = male.average,female.average.它给出了错误:
I want to create grouped barplot like x= age, y= male.average, female.average in beside. It gives error:
barplot.default(d)中的错误:'height'必须是向量或矩阵
推荐答案
假设我们有 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)))
这篇关于如何从数据框创建条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文