-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathcollege-majors.Rmd
204 lines (168 loc) · 5.08 KB
/
college-majors.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
---
title: "#tidytuesday screencast: College Major and Income"
author: "David Robinson"
output: html_document
---
This is the code behind an analysis of the 538 "College Major and Income" dataset from the [#tidytuesday project](https://github.com/rfordatascience/tidytuesday/tree/master/data/2018-10-16).
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(tidyverse)
library(scales)
theme_set(theme_light())
```
```{r}
recent_grads <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2018-10-16/recent-grads.csv")
majors_processed <- recent_grads %>%
arrange(desc(Median)) %>%
mutate(Major = str_to_title(Major),
Major = fct_reorder(Major, Median))
```
I'll also be aggregating by category.
```{r by_major_category}
by_major_category <- majors_processed %>%
filter(!is.na(Total)) %>%
group_by(Major_category) %>%
summarize(Men = sum(Men),
Women = sum(Women),
Total = sum(Total),
MedianSalary = sum(Median * Sample_size) / sum(Sample_size)) %>%
mutate(ShareWomen = Women / Total) %>%
arrange(desc(ShareWomen))
```
### What categories of majors make more money than others?
```{r}
majors_processed %>%
mutate(Major_category = fct_reorder(Major_category, Median)) %>%
ggplot(aes(Major_category, Median, fill = Major_category)) +
geom_boxplot() +
scale_y_continuous(labels = dollar_format()) +
expand_limits(y = 0) +
coord_flip() +
theme(legend.position = "none")
```
### What are the highest earning majors?
```{r}
majors_processed %>%
filter(Sample_size >= 100) %>%
head(20) %>%
ggplot(aes(Major, Median, color = Major_category)) +
geom_point() +
geom_errorbar(aes(ymin = P25th, ymax = P75th)) +
expand_limits(y = 0) +
scale_y_continuous(labels = dollar_format()) +
coord_flip() +
labs(title = "What are the highest-earning majors?",
subtitle = "Top 20 majors with at least 100 graduates surveyed. Bars represent the 25th to 75th percentile.",
x = "",
y = "Median salary of gradates")
```
### How does gender breakdown relate to typical earnings?
```{r}
majors_processed %>%
arrange(desc(Total)) %>%
head(20) %>%
mutate(Major = fct_reorder(Major, Total)) %>%
gather(Gender, Number, Men, Women) %>%
ggplot(aes(Major, Number, fill = Gender)) +
geom_col() +
coord_flip()
```
```{r}
library(ggrepel)
by_major_category %>%
mutate(Major_category = fct_lump(Major_category, 6)) %>%
ggplot(aes(ShareWomen, MedianSalary, color = Major_category)) +
geom_point() +
geom_smooth(method = "lm") +
geom_text_repel(aes(label = Major_category), force = .2) +
expand_limits(y = 0)
```
```{r}
library(plotly)
g <- majors_processed %>%
mutate(Major_category = fct_lump(Major_category, 4)) %>%
ggplot(aes(ShareWomen, Median, color = Major_category, size = Sample_size, label = Major)) +
geom_point() +
geom_smooth(aes(group = 1), method = "lm") +
scale_x_continuous(labels = percent_format()) +
scale_y_continuous(labels = dollar_format()) +
expand_limits(y = 0)
ggplotly(g)
```
```{r}
majors_processed %>%
select(Major, Total, ShareWomen, Sample_size, Median) %>%
lm(Median ~ ShareWomen, data = ., weights = Sample_size) %>%
summary()
```
```{r}
library(broom)
majors_processed %>%
select(Major, Major_category, Total, ShareWomen, Sample_size, Median) %>%
add_count(Major_category) %>%
filter(n >= 10) %>%
nest(-Major_category) %>%
mutate(model = map(data, ~ lm(Median ~ ShareWomen, data = ., weights = Sample_size)),
tidied = map(model, tidy)) %>%
unnest(tidied) %>%
filter(term == "ShareWomen") %>%
arrange(estimate) %>%
mutate(fdr = p.adjust(p.value, method = "fdr"))
```
```{r}
majors_processed %>%
filter(Sample_size >= 100) %>%
mutate(IQR = P75th - P25th) %>%
arrange(desc(IQR))
```
### Future Work
* Examining unemployment and fraction taking a job requiring a college degree
* Examining interquartile ranges
### Appendix
```{r}
majors_processed %>%
ggplot(aes(Sample_size, Median)) +
geom_point() +
geom_text(aes(label = Major), check_overlap = TRUE, vjust = 1, hjust = 1) +
scale_x_log10()
```
```{r}
knitr::knit_exit()
```
This is scrap work.
What were the most common *majors*? (Since there were 173, we're not going to show them all).
```{r}
majors_processed %>%
mutate(Major = fct_reorder(Major, Total)) %>%
arrange(desc(Total)) %>%
head(20) %>%
ggplot(aes(Major, Total, fill = Major_category)) +
geom_col() +
coord_flip() +
scale_y_continuous(labels = comma_format()) +
labs(x = "",
y = "Total # of graduates")
```
```{r}
majors_processed %>%
group_by(Major_category) %>%
summarize(Median = median(Median)) %>%
mutate(Major_category = fct_reorder(Major_category, Median)) %>%
ggplot(aes(Major_category, Median)) +
geom_col() +
scale_y_continuous(labels = dollar_format()) +
coord_flip()
```
What are the lowest earning majors?
```{r}
majors_processed %>%
filter(Sample_size >= 100) %>%
tail(20) %>%
ggplot(aes(Major, Median, color = Major_category)) +
geom_point() +
geom_errorbar(aes(ymin = P25th, ymax = P75th)) +
expand_limits(y = 0) +
coord_flip()
```