knitr::opts_chunk$set( collapse = TRUE, comment = "#>", echo=F, warning=F, error=F, fig.width = 6, fig.height = 4, fig.align = "center" )
library(retirementData) library(magrittr) library(kableExtra) library(scales) library(readr) library(dplyr) library(ggplot2)
data("retirementLoc")
retirementLoc %>% select(pop_2020) %>% summarize(min = min(pop_2020, na.rm = T), ptile_25 = quantile(pop_2020, .25, na.rm = T), mean = mean(pop_2020, na.rm = T), median = median(pop_2020, na.rm = T), ptile_75 = quantile(pop_2020, .75, na.rm = T), max = max(pop_2020, na.rm = T)) %>% slice(n = 1) %>% kbl(format.args = list(big.mark = ",")) %>% kable_styling()
library(scales) retirementLoc %>% ggplot() + aes(pop_2020) + geom_density() + scale_x_continuous(name = "", labels = comma) + labs(title = "U.S. Population by County 2020") + theme_minimal()
retirementLoc %>% select(pct_pop_change) %>% summarize(min = min(pct_pop_change, na.rm = T), ptile_25 = quantile(pct_pop_change, .25, na.rm = T), mean = mean(pct_pop_change, na.rm = T), median = median(pct_pop_change, na.rm = T), ptile_75 = quantile(pct_pop_change, .75, na.rm = T), max = max(pct_pop_change, na.rm = T)) %>% slice(n = 1) %>% kbl(format.args = list(big.mark = ",")) %>% kable_styling(full_width = T, bootstrap_options = c("striped", "hover", "condensed"))
retirementLoc %>% ggplot() + aes(pct_pop_change) + geom_density() + labs(title = "U.S. Population Change by County 2010 - 2020") + theme_minimal()
retirementLoc %>% arrange(desc(pop_2020)) %>% slice_head(n = 10) %>% select(fips, state, county, pop_2020, pct_pop_change) %>% kbl(format.args = list(big.mark = ",")) %>% kable_styling(full_width = T, bootstrap_options = c("striped", "hover", "condensed"))
retirementLoc %>% arrange(desc(pop_2020)) %>% slice_tail(n = 10) %>% select(fips, state, county, pop_2020, pct_pop_change) %>% kbl(format.args = list(big.mark = ",")) %>% kable_styling(full_width = T, bootstrap_options = c("striped", "hover", "condensed"))
retirementLoc %>% arrange(desc(pct_pop_change)) %>% slice_head(n = 10) %>% select(fips, state, county, pop_2020, pct_pop_change) %>% kbl(format.args = list(big.mark = ",")) %>% kable_styling(full_width = T, bootstrap_options = c("striped", "hover", "condensed"))
retirementLoc %>% arrange(pct_pop_change) %>% slice_head(n = 10) %>% select(fips, state, county, pop_2020, pct_pop_change) %>% kbl(format.args = list(big.mark = ",")) %>% kable_styling(full_width = T, bootstrap_options = c("striped", "hover", "condensed"))
retirementLoc %>% dplyr::filter(pop_2020 > 1e5) %>% select(fips, state, county, pop_2020, pct_pop_change) %>% arrange(desc(pct_pop_change)) %>% slice_head(n = 10) %>% kbl(format.args = list(big.mark = ",")) %>% kable_styling(full_width = T, bootstrap_options = c("striped", "hover", "condensed"))
retirementLoc %>% dplyr::filter(pop_2020 > 1e5) %>% select(fips, state, county, pop_2020, pct_pop_change) %>% arrange(pct_pop_change) %>% slice_head(n = 10) %>% kbl(format.args = list(big.mark = ",")) %>% kable_styling(full_width = T, bootstrap_options = c("striped", "hover", "condensed"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.