The goal of leaidr is to provide an easy way to map U.S. school districts in R.
You can install the development version of this package from GitHub with:
# install.packages("devtools")
devtools::install_github("ivelasq/leaidr")
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.
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.
Once you have the shapefile, you can plot using {leaflet} and {ggplot2}.
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()
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}.
Many thanks to datalorax for the incredible improvements to this package.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.