Created
October 24, 2016 17:03
-
-
Save r-conway/4bdc1f34a07e97d55a47eb823105f2be 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
#line graph for race for married women | |
#load libraries | |
library(readr) | |
library(dplyr) | |
library(ggplot2) | |
library(RColorBrewer) | |
library(scales) | |
#load data | |
a <- read_csv('data/usa_00013.csv',col_types=cols(PERWT=col_double())) | |
#filter out those under 16 and over 65 | |
b <- a %>% filter(AGE>= 16 & AGE<= 65) | |
#Remove Alaska and Hawaii | |
bb <- b %>% filter(YEAR>=1960 | !(STATEFIP %in% c(2,15))) | |
#assign sex | |
c <- bb %>%mutate(Sex=factor(SEX, labels=c('Male','Female'))) | |
#Remove Men | |
d <- c %>% filter(Sex=='Female') | |
#Remove single women | |
e <- d %>% filter(MARST<3) | |
#Create Race catagories | |
f <- e %>% mutate(Race=factor(ifelse(RACE==1,1, | |
ifelse(RACE==2,2, | |
ifelse(RACE==3,3,4))))) | |
g <- f %>% mutate(Race=factor(Race,labels=c('White','Black','Native American','Asian'))) | |
#Creat Occ avriable | |
h <- g %>% mutate(Occ=factor(ifelse(OCC1950>=980,1,2))) | |
#Split into employed/unemployed | |
i <- h %>% mutate(Occ=factor(Occ,labels=c('Not Employed','Employed'))) | |
#Group to calculate total married women of each race for each year | |
j <- i %>% group_by(YEAR,Race) %>% summarise(Total=sum(PERWT)) | |
#group to calculate total percent employed of married women for each year | |
k <- i %>% group_by(YEAR,Race,Occ) %>% summarise(Number=sum(PERWT)) | |
#link so we can calculate percent | |
l <- left_join(k,j,by=c('YEAR','Race')) | |
#Remove unemployed | |
m <- l %>% filter(Occ=='Employed') | |
#Calculate percentages | |
n <- m %>% mutate(Percent=Number*100/Total) | |
#Graph | |
ggplot(data=n, aes(x=YEAR, y=Percent, group=Race, colour=Race)) + | |
geom_line() + | |
labs(title='Percent Employment of Married Women by Race from 1920-1970', x='Year',colour='Race of Mother') + | |
scale_y_continuous(limits=c(0,100), breaks=c(0,25,50,75,100), | |
labels=c('0%','25%','50%','75%','100%')) | |
ggsave('Fig2B.pdf',width=10, height=7.5) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment