knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) library(dplyr) library(ggplot2) library(sf)
The censusviz
package provides an interface for exploring and visualizing historical racial demographic census data (1950-2020) sourced from IPUMS for any region in the United States (by county). The package provides functionality for visualizing the data on leaflet maps as well as for accessing the data in an accessible, tidy format such that the user can then create their own visualizations.
Since the data is very large, it is hosted on GitHub and is not contained in the package itself. The package includes a few smaller samples of the data as examples. The raw data can be accessed here. See the vignette for more details.
This package was inspired by the nepm
package. The nepm package was initially created as part of a DSC-WAV project in fall 2021 funded by the NSF with the goal of creating an interactive map to visualize the demographics over time of Springfield, MA in partnership with New England Public Media.
censusviz
is hosted on GitHub and can be installed by running the following function:
``` {r, eval = FALSE} remotes::install_github("rporta23/censusviz")
```r library(censusviz)
We have included 5 sample datasets to demonstrate the functionality of the package. These datasets consist of:
boston_sample
sanfrancisco_sample
manhattan sample
Users can visualize these datasets on a leaflet map using the base_map()
and add_people()
functions, as demonstrated in Example 1.
get_data_wide()
function:madison_data_wide
This dataset can be used to visualize the census tract boundary lines for Madison County, NY on a leaflet map using the base_map()
and add_tracts()
functions, as demonstrated in the vignette.
get_data_long()
function:boston_data_long
This dataset can be used for exploratory analysis of racial demographic data for Suffolk County, MA using dplyr
and ggplot2
functionality, as demonstrated in Example 2
See the vignette and full documentation for more information on how to access and visualize the data for any county in the U.S.
Visualize spatial distribution of racial demographics for any census year between 1950-2020 using add_people()
. Dataframes with locations of dots to plot on the map for Boston, MA, Manhattan, NY, and San Francisco, CA, are included in the package. However, you can get the data for any county in the U.S. using the functions provided in censusviz
. See the vignette for more details on how to create this type of map for any region in the U.S.
# create map for Boston, MA in 1960 base_map() %>% add_people(1960, boston_sample)
{height=300}
# create map for Boston, MA in 2000 base_map() %>% add_people(2000, boston_sample)
{height=300}
Create a line graph to show changes in demographics over time for Boston (Suffolk County), MA. The sample of data to create this graph for Boston is included in the package. See the vignette for details on how to create this type of graph for any region.
head(boston_data_long)
# group by year and race_label and summarize to create dataframe for line graph data_long_sum <- boston_data_long %>% group_by(year, race_label) %>% summarize(total = sum(n)) # create line graph to show change over time in demographics ggplot(data_long_sum, aes(x = year, y = total, color = race_label)) + geom_line() + labs( title = "Change in Racial Demographics over time in Suffolk County, MA", x = "Year", y = "Number of People", color = "Race" )
If you are interested in exploring U.S. census data, see related package tidycensus
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.