Step 1: Load packages
library(viridis)
## Loading required package: viridisLite
library(sf)
## Linking to GEOS 3.9.1, GDAL 3.4.3, PROJ 7.2.1; sf_use_s2() is TRUE
library(rworldmap)
## Loading required package: sp
## ### Welcome to rworldmap ###
## For a short introduction type : vignette('rworldmap')
library(rgeos)
## rgeos version: 0.5-9, (SVN revision 684)
## GEOS runtime version: 3.9.1-CAPI-1.14.2
## Please note that rgeos will be retired by the end of 2023,
## plan transition to sf functions using GEOS at your earliest convenience.
## GEOS using OverlayNG
## Linking to sp version: 1.5-0
## Polygon checking: TRUE
library(ggdendro)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:rgeos':
##
## intersect, setdiff, union
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(sf)
library(tigris)
## To enable caching of data, set `options(tigris_use_cache = TRUE)`
## in your R script or .Rprofile.
library(ggplot2)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(htmlwidgets)
Source and About the Data The following data was obtained from the US Bureau of Economic analysis (link below), and is the percentage of total compensation within each state that was made up by recreation in 2020. https://www.bea.gov/data/special-topics/outdoor-recreation
Approach and Design In this I was looking to communicate how large of a part recreation played in each state’s economy for that fiscal year, and found the above metric to be most suitable as it is directly tied to income.
To represent this I used choropleth map of the US with a wide range of colors to ultimately parse out the differences from state to state. To enable further analysis, I have also made the map interactive so we can see the respective percentages for each state.
Interpretation What can be seen below is that much of the Mountain West appears to be above the national average in terms of reliance on recreation, although there are a couple of exceptions, notable Maine, Vermont and Florida.
#pull in data
rec<-read.csv("Recreation-State.csv")
#head(rec)
#pair data with map
recreation <- map_data("state")%>%
left_join(rec, by = c("region" = "X"))
#create chloropleth map using gg tools
plot_rec <- ggplot(data = recreation, mapping = aes(x = long, y = lat, group = group, fill = Percent_TotalComp, text = paste("% of State Total:", round(Percent_TotalComp,1), sep = " "))) +
geom_polygon(color = "White")+
ggdendro::theme_dendro() +
scale_fill_viridis(option="magma", direction=-1)+
ggtitle("Recreation as Percent of Total Employee Compensation in 2020")+
labs(fill = "Percent \nTotal State \nCompensation")+
coord_map()
plot_rec
#create chloropleth map using gg tools
plot_rec <- ggplot(data = recreation, mapping = aes(x = long, y = lat, group = group, fill = Percent_TotalComp, text = paste("% of State Total:", round(Percent_TotalComp,1), sep = " "))) +
geom_polygon(color = "White")+
ggdendro::theme_dendro() +
scale_fill_viridis(option="magma", direction=-1)+
ggtitle("Recreation as Percent of Total Employee Compensation in 2020")+
labs(fill = "Percent \nTotal State \nCompensation")
#use plotly to make interactive
plot_rec_plotly <- ggplotly(plot_rec, tooltip = "text")
#show map
plot_rec_plotly