Please load the 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 data.
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 Facebook use.
pew <-pew %>%
mutate(Facebook = as.factor(web1c)) %>%
mutate(Facebook = fct_recode(Facebook,
"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"))
Create a table based on education and number of individuals. This table below depicts the number of individuals in each eduational cateogry and is organized from lowest level to highest level of education.
pew %>%
drop_na(education) %>%
count(education)
Create a table to see how many people in this data set use Facebook.
pew %>%
drop_na(Facebook) %>%
count(Facebook)
Next we need to factor in how many people are acutally using or not using Facebook along with their education level and how many people in each subset. The table below is a representation of those factors.
pew %>%
drop_na(Facebook, education) %>%
count(education, Facebook)
Next we need to graph Facebook use by using a more linear approach. This graph compares the number of people and their educational level along with whether or not they use facebook. From the data, it can be inferred that those with a higher education level use Facebook more than those who are a HS graduate or lower.
pew %>%
drop_na(education, Facebook) %>%
ggplot(aes(x = education, fill = Facebook)) +
geom_bar(position = 'fill') +
scale_fill_viridis_d() +
coord_flip() +
labs(title = "Facebook Use by Education Level", x = "Education Level", y = "Number of people")
Collapse education level into this table below.
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)
However in the table above, you can see that the data is actually more evenly distributed. The category,“No college degree” begins at a high school graduate level and moves lower. The category “College degree” begins at an Associate degree and higher ending with a Grad degree.
pew %>%
drop_na(education_simple, Facebook) %>%
count(education_simple, Facebook)
The table above depicts the diference in the number of people who do or don’t use Facebook and is shown in relation to their education level.
pew %>%
drop_na(education_simple, Facebook) %>%
ggplot(aes(x = education_simple, fill = Facebook)) +
geom_bar(position = 'fill') +
scale_fill_viridis_d() +
coord_flip() +
labs(title= "Facebook Use by Education Level", y = "Number of People ", x = "Education Level")
Finally, the graph above was created to better compare people’s education level with their use of Facbook. As one can see, the levels are pretty close. It does appear that individuals with at least a college degree are slightly more likely to use Facebook than those with a lower education level.