njcensus is an R package for downloading, processing, and analyzing New Jersey census demographic data. It supports both 2010 and 2020 decennial census years and 2020-2023 population estimates. This package provides tools for working with demographic indicators across counties and municipalities.
- Downloads demographic data from the Census Bureau API
- Processes population data by race and gender
- Stores results in a DuckDB database for efficient querying
- Supports both 2010 and 2020 census years
- Includes population estimates for 2021-2023
- Handles county and municipality level data
You can install the development version of njcensus from GitHub with:
# install.packages("devtools")
devtools::install_github("PrigasG/njcensus")
# Install stable release
install.packages("https://github.com/PrigasG/njcensus/releases/download/v1.0.0/njcensus_1.0.0.tar.gz",
repos = NULL,
type = "source")library(njcensus)
# Initialize using pre-packaged data (recommended)
init_census_data()
# Or fetch fresh data from Census API (optional)
init_census_data(use_packaged_data = FALSE)
# Initialize without population estimates
init_census_data(include_pop_estimates = FALSE)# Get preview of all demographics
preview <- get_census_data()
# Get data for white males in 2020 (default)
default_data <- get_census_data("white")
# Get specific data
asian_female_2010 <- get_census_data("asian", "female", 2010)
# Filter by county
atlantic_data <- get_census_data("white", counties = "Atlantic")
# Filter by municipality
jersey_city_data <- get_census_data("white", municipalities = "Jersey City")# Get population estimates data (agesex is default)
pop_data <- get_pop_estimates()
# Get specific file type
alldata <- get_pop_estimates(file_type = "alldata")
# Filter by county and year
atlantic_2023 <- get_pop_estimates(counties = "Atlantic", years = 2023)The package includes pre-packaged Census data for better performance and reliability:
- Faster initialization
- No API rate limits
- Works offline
- Consistent data access
The package supports the following demographic groups:
- white
- boaa (Black or African American)
- aian (American Indian and Alaska Native)
- asian
- nhpi (Native Hawaiian and Pacific Islander)
- others
- two_more (Two or more races)
Process census data for a specific year:
# Process 2020 census data
process_census_data(2020)Querying demographic data
# Get data for specific demographics
data <- get_census_data(
demographic = "asian",
gender = "female",
year = 2020
)
# View the first few rows
head(data)Data is stored in a DuckDB database with tables named according to the pattern:
- Census data: {demographic}{gender}{year} (e.g., white_male_2020)
- Population estimates: pop_estimates_{file_type} (e.g., pop_estimates_agesex)
Please submit issues and pull requests on GitHub. Contributions are welcome!
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
George Arthur - Initial work
- Census Bureau API documentation
- DuckDB documentation
- R Spatial community