Skip to content

Instantly share code, notes, and snippets.

@kszela24
Last active May 1, 2016 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kszela24/54fc0de27af7dc71b083927d59609c5d to your computer and use it in GitHub Desktop.
Save kszela24/54fc0de27af7dc71b083927d59609c5d to your computer and use it in GitHub Desktop.
#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