-
-
Save kszela24/f74bdebdf05b6153690724a6c387ab58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Tally the totals for each level of education. | |
education_totals = summarise(education_numbers, | |
Both = sum(instance.weight), | |
Males = sum(instance.weight[sex == "Male"]), | |
Females = sum(instance.weight[sex == "Female"])) | |
education_numbers_both = group_by(education_numbers, education) %>% | |
summarise(., | |
Both = (sum(instance.weight) / education_totals$Both) * 100) | |
education_numbers_males = group_by(education_numbers, education, sex) %>% | |
summarise(., | |
pct = (sum(instance.weight[sex == "Male"]) / education_totals$Males) * 100) | |
education_numbers_females = group_by(education_numbers, education, sex) %>% | |
summarise(., | |
pct = (sum(instance.weight[sex == "Female"]) / education_totals$Females) * 100) | |
education_numbers_males$pct = education_numbers_males$pct + education_numbers_females$pct | |
#Getting education by income | |
education_income = group_by(education_numbers, education, sex) %>% | |
summarise(., | |
count_geq50 = sum(instance.weight[X == "50000+." & age >= 18]), | |
count_l50 = sum(instance.weight[X == "-50000" & age >= 18]), | |
pct = (count_geq50 / (count_l50 + count_geq50)) * 100) %>% | |
select(., education, sex, pct) | |
#Stack data for ggplot2 | |
population.ident = rep("Percent of Total Population", NROW(education_numbers_males)) | |
income.ident = rep("Percent with Certain Education with Income >$50,000", NROW(education_income)) | |
education_numbers_males$Identifier = population.ident | |
education_income$Identifier = income.ident | |
education_stacked = rbind(education_numbers_males, education_income) | |
#Male/female side by side education/income vertically | |
educationPlot_mf = ggplot(education_stacked, aes(x = education, y = pct)) + | |
geom_bar(stat = "identity", aes(fill = education)) + | |
theme_bw() + | |
scale_fill_discrete(name = "Education") + | |
ggtitle("Education Grid 94' - 95'") + | |
xlab("") + | |
ylab("") + | |
theme(axis.ticks = element_blank(), axis.text.x = element_blank()) + | |
facet_grid(Identifier ~ sex) | |
educationPlot_mf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment