想象中的R汇总统计

问题描述 投票:-6回答:1

我怎样才能创建饼图和条形图,从数据的本摘要R:

gender        race.ethnicity    parental.level.of.education
female:518    group A: 89       associate's degree:222  
male  :482    group B:190       bachelor's degree :118  
              group C:319       high school       :196 
              group D:262       master's degree   : 59
              group E:140       some college      :226  
                                some high school  :179       
r
1个回答
1
投票

尝试:

gender <- c(518, 482)
names(gender) <- c("male", "female")
pie(gender, names(gender))
barplot(gender)

同为其他类别,例如

groups <- c(89, 190, 319, 262, 140)
names(groups) <- c("A", "B", "C", "D", "E")
pie(groups, names(groups))
barplot(groups)

收益:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.