Skip to content
/ leaidr Public

An R Package for U.S. School District Shapefiles

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

ivelasq/leaidr

Repository files navigation

leaidr

The goal of leaidr is to provide an easy way to map U.S. school districts in R.

Installation

You can install the development version of this package from GitHub with:

# install.packages("devtools")
devtools::install_github("ivelasq/leaidr")

About

School districts in the U.S. have associated local education agency identification numbers (LEAID) used in the National Center for Education Statistics (NCES) Common Core of Data. These are very useful because if you have other datasets with NCES ID’s, then you can (sometimes easily) join them.

The original shapefiles can be found on the NCES site. These files are from 2019. All the state-level shapefiles are saved here.

Get the U.S. Shapefile

Load the shapefile for the entire U.S. using lea_get() and the state abbreviation. Loading may take a while. You will have to load the shapefile anytime you’re in a new directory/project.

You must have a GITHUB_PAT before you can run lea_get(). You can set a token in your developer settings and save it in your R Environment. More info can be found in Happy git with R.

Use the Data

Once you have the shapefile, you can plot using {leaflet} and {ggplot2}.

{ggplot2} Example

library(leaidr)

tn <- lea_get("tn")
#> Warning in OGRSpatialRef(dsn, layer, morphFromESRI = morphFromESRI, dumpSRS
#> = dumpSRS, : Discarded datum D_unknown in CRS definition: +proj=longlat
#> +ellps=GRS80 +no_defs
#> OGR data source with driver: ESRI Shapefile 
#> Source: "/private/var/folders/pj/nmg9b8_93dq4kwt8nt2d4cj40000gn/T/Rtmp5IIOU1/47", layer: "47"
#> with 158 features
#> It has 18 fields

tn %>% 
  sf::st_as_sf() %>% 
  ggplot2::ggplot() +
  ggplot2::geom_sf()

Download all states

If you use lea_get() (i.e., with state = NULL), you get all the district shapefiles for the whole U.S. via ROpenSci’s {piggyback}.

Acknowlegements

Many thanks to datalorax for the incredible improvements to this package.