This is from Wikipedia.
I want to make similar barplot with data below.
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")
What I am trying to do is
1) make a barplot just like above: the frequency of audit$Income.
2) make two barplot devided by audit$TARGET_Adjusted.
I tried for the first one like below. And it didn't work.
fre <- tapply(audit$income, audit$TARGET_Adjusted, table)
barplot(fre)
Can you please let me know how to?