library(tidycensus)
library(tidyverse)
library(stringr)
library(scales)
library(plotly)
graduate_degree <- get_acs(
geography = "county",
variables = "DP02_0066P",
year = 2021
)
graduate_degree_mi_largest <- graduate_degree %>%
#using the str_detect function from stringr here, instead of splitting the name column like Dr. Walker
filter(str_detect(GEOID, "^26")) %>%
arrange(desc(estimate))
#head of counties with largest percent of graduate degree holders
head(graduate_degree_mi_largest)
## # A tibble: 6 × 5
## GEOID NAME variable estimate moe
## <chr> <chr> <chr> <dbl> <dbl>
## 1 26161 Washtenaw County, Michigan DP02_0066P 30.3 0.7
## 2 26125 Oakland County, Michigan DP02_0066P 21.3 0.3
## 3 26089 Leelanau County, Michigan DP02_0066P 19.6 1.6
## 4 26065 Ingham County, Michigan DP02_0066P 18.4 0.6
## 5 26083 Keweenaw County, Michigan DP02_0066P 16.1 3.3
## 6 26077 Kalamazoo County, Michigan DP02_0066P 15.8 0.6
graduate_degree_mi_smallest <- graduate_degree %>%
#using the str_detect function from stringr here, instead of splitting the name column like Dr. Walker
filter(str_detect(GEOID, "^26")) %>%
arrange(estimate)
#head of counties with smallest percent of graduate degree holders
head(graduate_degree_mi_smallest)
## # A tibble: 6 × 5
## GEOID NAME variable estimate moe
## <chr> <chr> <chr> <dbl> <dbl>
## 1 26085 Lake County, Michigan DP02_0066P 3.7 0.7
## 2 26117 Montcalm County, Michigan DP02_0066P 4.3 0.6
## 3 26067 Ionia County, Michigan DP02_0066P 4.4 0.6
## 4 26113 Missaukee County, Michigan DP02_0066P 4.4 0.8
## 5 26131 Ontonagon County, Michigan DP02_0066P 4.4 0.7
## 6 26157 Tuscola County, Michigan DP02_0066P 4.4 0.6
md_plot_errorbar
Fig 1. Michigan counties with the highest percentage of graduate degree holders (top 25).
plotly_chart <- ggplotly(md_plot_errorbar, tooltip = "x")
plotly_chart <- plotly_chart %>%
layout(
annotations = list(
list(
text = "Counties in Michigan",
x = 0,
y = 1.05,
xref = "paper",
yref = "paper",
showarrow = FALSE,
font = list(size = 16)
),
list(
#use \n to drop text to the next line
text = "Data acquired with R and tidycensus. Error bars \n represent margin of error around estimates.",
x = 1,
y = -0.01,
xref = "paper",
yref = "paper",
showarrow = FALSE,
font = list(size = 10)
)
)
)
plotly_chart
Fig 2. Michigan counties with the highest percentage of graduate degree holders (top 25), as an interactive.