简体   繁体   中英

visualise summary statistics in R

How can I create pie chart and bar graph in R from this summary of data:

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       

Try:

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

Same for your other categories, eg

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

returns:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM