2

数字频率表

这是来自维基百科

我想用下面的数据制作类似的条形图。

audit<-structure(list(ID = c(1004641L, 1010229L, 1024587L, 1038288L, 
1044221L, 1047095L, 1047698L, 1053888L, 1061323L, 1062363L), 
Age = c(38L, 35L, 32L, 45L, 60L, 74L, 43L, 35L, 25L, 22L), 
Employment = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L), .Label = c("Consultant", "Private", "PSFederal", 
"PSLocal", "PSState", "SelfEmp", "Unemployed", "Volunteer"
), class = "factor"), Education = structure(c(3L, 1L, 5L, 
2L, 3L, 5L, 2L, 12L, 1L, 5L), .Label = c("Associate", "Bachelor", 
"College", "Doctorate", "HSgrad", "Master", "Preschool", 
"Professional", "Vocational", "Yr10", "Yr11", "Yr12", "Yr1t4", 
"Yr5t6", "Yr7t8", "Yr9"), class = "factor"), Marital = structure(c(5L, 
1L, 2L, 3L, 3L, 3L, 3L, 3L, 2L, 1L), .Label = c("Absent", 
"Divorced", "Married", "Married-spouse-absent", "Unmarried", 
"Widowed"), class = "factor"), Occupation = structure(c(12L, 
14L, 2L, 10L, 3L, 12L, 3L, 6L, 2L, 11L), .Label = c("Cleaner", 
"Clerical", "Executive", "Farming", "Home", "Machinist", 
"Military", "Professional", "Protective", "Repair", "Sales", 
"Service", "Support", "Transport"), class = "factor"), Income = c(8, 
7, 1, 2, 7, 3, 4, 5, 1, 5), Gender = structure(c(1L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L), .Label = c("Female", "Male"
), class = "factor"), Deductions = c(0, 0, 0, 0, 0, 0, 0, 
0, 0, 0), Hours = c(72L, 30L, 40L, 55L, 40L, 30L, 50L, 40L, 
40L, 37L), IGNORE_Accounts = structure(c(31L, 18L, 31L, 31L, 
31L, 31L, 31L, 31L, 31L, 31L), .Label = c("Canada", "China", 
"Columbia", "Cuba", "Ecuador", "England", "Fiji", "Germany", 
"Greece", "Guatemala", "Hong", "Hungary", "India", "Indonesia", 
"Iran", "Ireland", "Italy", "Jamaica", "Japan", "Malaysia", 
"Mexico", "NewZealand", "Nicaragua", "Philippines", "Poland", 
"Portugal", "Scotland", "Singapore", "Taiwan", "Thailand", 
"UnitedStates", "Vietnam", "Yugoslavia"), class = "factor"), 
RISK_Adjustment = c(0L, 0L, 0L, 7298L, 15024L, 0L, 22418L, 
0L, 0L, 0L), TARGET_Adjusted = c(0L, 0L, 0L, 1L, 1L, 0L, 
1L, 0L, 0L, 0L)), .Names = c("ID", "Age", "Employment", "Education", 
"Marital", "Occupation", "Income", "Gender", "Deductions", "Hours", 
"IGNORE_Accounts", "RISK_Adjustment", "TARGET_Adjusted"), row.names = c(NA, 
10L), class = "data.frame")

我想做的是

1) 像上面一样制作一个条形图:audit$Income 的频率。

2) 制作两个由 audit$TARGET_Adjusted 划分的条形图。

我尝试了第一个,如下所示。它没有用。

fre <- tapply(audit$income, audit$TARGET_Adjusted, table)
barplot(fre)

你能告诉我怎么做吗?

4

0 回答 0