-
-
Save kszela24/54fc0de27af7dc71b083927d59609c5d 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
#Load libraries. | |
library(ggplot2) | |
library(dplyr) | |
library(RColorBrewer) | |
#Get data. | |
census <- read.csv("census-income.csv", stringsAsFactors = T, strip.white = T) | |
#Subset census data by race and sex. | |
ratio_race_of_worker = group_by(census, race, sex) %>% | |
summarise(., | |
count_geq50 = sum(instance.weight[X == "50000+." & age >= 18]), | |
count_l50 = sum(instance.weight[X == "-50000" & age >= 18]), | |
pct_geq50 = (count_geq50 / (count_l50 + count_geq50)) * 100) | |
#Graph by race and sex. | |
racePlot_sex = ggplot(ratio_race_of_worker, aes(x = race, y = pct_geq50)) + | |
geom_bar(stat = "identity", aes(fill = race)) + | |
scale_fill_brewer(name = "Race", palette = "Set1") + | |
ggtitle("Income by Race 94' - 95'") + | |
xlab("") + | |
ylab("Percent of Race with Income >50k") + | |
theme(axis.ticks = element_blank(), axis.text.x = element_blank()) + | |
facet_wrap( ~ sex) | |
racePlot_sex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment