generated from KSUDS/p2_data
-
Notifications
You must be signed in to change notification settings - Fork 1
/
draft.R
49 lines (36 loc) · 997 Bytes
/
draft.R
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
library(tidyverse)
library(ggplot2)
library(waffle)
library(dplyr)
httpgd::hgd()
httpgd::hgd_browse()
dat <- read_csv("https://github.com/fivethirtyeight/guns-data/raw/master/full_data.csv") %>%
select(-...1)
dat <- dat %>%
mutate(age_group = case_when(
age < 18 ~ "Young",
TRUE ~ "old"
))
glimpse(dat)
dat_pop <- tibble(
race = c("Asian/Pacific Islander",
"Black", "Hispanic",
"Native American/Native Alaskan", "White"),
N = 331449281 * c(.061, .134, .185, .013, .763))
dat_pop
dat_merge <- merge(dat, dat_pop)
glimpse(dat_merge)
dat_counts <- dat %>%
count(race, year)
dat_counts %>%
left_join(dat_pop, by = "race")
datrace <- dat %>% group_by(race, education)
dat_merge %>%
drop_na() %>%
group_by(race) %>%
summarize(nn = n()) %>%
ungroup()
mutate(perc = nn / N * 100) %>%
ggplot(aes(values = round(perc), fill = race)) +
geom_waffle()
datrace