load required package:
library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.1.0 ✔ purrr 0.2.5
## ✔ tibble 2.0.0 ✔ dplyr 0.7.8
## ✔ tidyr 0.8.2 ✔ stringr 1.3.1
## ✔ readr 1.3.1 ✔ forcats 0.3.0
## ── Conflicts ─────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
Read in the date:
pew <- read_csv("January 3-10, 2018 - Core Trends Survey/January 3-10, 2018 - Core Trends Survey - CSV.csv")
## Parsed with column specification:
## cols(
## .default = col_double(),
## usr = col_character(),
## `pial11ao@` = col_character()
## )
## See spec(...) for full column specifications.
Recode snapchate use
pew <- pew %>%
mutate(snapchat = as.factor(web1d))%>%
mutate(snapchat = fct_recode(snapchat,
"Yes" = "1",
"No" = "2",
NULL = "8",
NULL = "9"))
Recode education
pew <- pew %>%
mutate(education = as.factor(educ2))%>%
mutate(education = fct_recode(education,
"Less than HS" = "1",
"Some HS" = "2",
"HS graduate" = "3",
"Some college" = "4",
"Associate degree" = "5",
"College degree" = "6",
"Some grad school" = "7",
"Grad degree" = "8",
NULL = "98",
NULL = "99"))
pew %>%
drop_na(education)%>%
count (education)
pew %>%
drop_na(snapchat) %>%
count(snapchat)
pew%>%
drop_na(snapchat, education) %>%
count(education, snapchat)
pew %>%
drop_na(education, snapchat) %>%
ggplot(aes(x = education, fill = snapchat)) +
scale_fill_viridis_d()+
geom_bar( position = "fill") +
coord_flip()+
labs(title = "Snapchat use by education level")
Collapse education level into two levels:
pew <- pew %>%
mutate(education_simple = fct_collapse(education,
college_degree = c("Associate degree",
"College degree",
"Some grad school",
"Grad degree"),
no_college_degree = c("Less than HS",
"Some HS",
"HS graduate",
"Some college")))
pew%>%
drop_na(education_simple)%>%
count(education_simple)
pew%>%
drop_na(education_simple, snapchat) %>%
count(education_simple, snapchat)
pew %>%
drop_na(education_simple, snapchat) %>%
ggplot(aes(x = education_simple, fill = snapchat)) +
scale_fill_viridis_d()+
geom_bar( position = "fill") +
coord_flip()+
labs(title= "Snapchat use by education level")