Created
November 14, 2016 15:25
-
-
Save anonymous/d1b33f97df83bf8ba27b7daed974760b to your computer and use it in GitHub Desktop.
FP Figure 2
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
#FP Figure 2 | |
#load packages | |
library(readr) | |
library(dplyr) | |
library(ggplot2) | |
library(RColorBrewer) | |
library(scales) | |
#read csv | |
csv <- read_csv("~/Desktop/usa_00028.csv") | |
#only women and older than 22 | |
csv_new <- csv %>% filter(SEX==2 & AGE>=22) | |
#recode race | |
race_grouped <- csv_new %>% mutate(Race_2=factor(ifelse(HISPAN>0,1, | |
ifelse(RACESING==1,2, | |
ifelse(RACESING==2,3, | |
ifelse(RACESING==3,4, | |
ifelse(RACESING==4,5,6))))))) | |
levels(race_grouped$Race_2) <- c('Hispanic','White','Black','Native American','Asian','Other') | |
#filter out 'other' category | |
race_grouped2 <- race_grouped %>% filter(Race_2!='Other') | |
#make marriage variable | |
mstatus <- race_grouped2 %>% mutate(MStatus=ifelse(MARST==6,'Unmarried','Married')) | |
#make degree/no degree variable | |
educ <- mstatus %>% mutate(EducLev=ifelse(EDUCD>=101 & EDUCD<=116, 'Degree', 'No Degree')) | |
#calculate number with degrees | |
num <- educ %>% group_by(YEAR, EducLev, MStatus, Race_2) %>% summarise(num=sum(PERWT)) | |
#calculate total number | |
total_num <- educ %>% group_by(YEAR, MStatus, Race_2) %>% summarise(tnum=sum(PERWT)) | |
#join | |
joined <- left_join(total_num,num) | |
#calc percent | |
percentages <- joined %>% mutate(pct=num/tnum*100) | |
# plot the percent with a college degree | |
percentages <- percentages %>% filter(EducLev=='Degree') | |
#plot it, line | |
ggplot(percentages,aes(x=YEAR,y=pct,color=Race_2)) + | |
geom_line() + geom_point() + | |
facet_grid(MStatus~.) + | |
labs(x='Year',y='Percent',fill='Sex',title='Percent of Women over 22 with a College Degree by Race, 1940-2000') + | |
scale_y_continuous(labels=scales::comma) + | |
scale_x_continuous(breaks=c(1940,1960,1980,2000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment