Skip to content

Instantly share code, notes, and snippets.

@benjamin-chan
Created June 6, 2025 19:24
Show Gist options
  • Save benjamin-chan/0a45a34b6ca05c27c32d636cf97d21f1 to your computer and use it in GitHub Desktop.
Save benjamin-chan/0a45a34b6ca05c27c32d636cf97d21f1 to your computer and use it in GitHub Desktop.
Scrape Public Libraries Survey (PLS) data

Public Libraries Survey (PLS)

Link: https://www.imls.gov/research-evaluation/surveys/public-libraries-survey-pls

Load packages

library(magrittr)
library(tidyverse)
## ── Attaching core tidyverse packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ tidyr::extract()   masks magrittr::extract()
## ✖ dplyr::filter()    masks stats::filter()
## ✖ dplyr::lag()       masks stats::lag()
## ✖ purrr::set_names() masks magrittr::set_names()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(knitr)

Download public domain data

url <- "https://www.imls.gov/sites/default/files/2024-06/pls_fy2022_csv.zip"
f <- tempfile()
download.file(url, f)

Unzip administrative entity (AE) data and import as a data frame

csvFile <- unzip(f, list = TRUE) %>% filter(grepl("AE", Name)) %>% pull(Name)
unzip(f, files = csvFile)
df <- read_csv(csvFile)
## Rows: 9248 Columns: 192
## ── Column specification ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## chr (103): STABR, FSCSKEY, LIBID, LIBNAME, ADDRESS, CITY, ZIP, ZIP4, ADDRES_...
## dbl  (89): PHONE, POPU_LSA, POPU_UND, CENTLIB, BRANLIB, BKMOB, MASTER, LIBRA...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Rank Multnomah County Library

  • Compare to similar sized or larger library service areas
  • Rank total circulation and per capita circulation
    • Exclude missing -1 or temporarily closed administrative entity -3 values
benchmark <- df %>% filter(grepl("MULTNOMAH", LIBNAME)) %>% pull(POPU_UND)
## Warning: There were 16 warnings in `filter()`.
## The first warning was:
## ℹ In argument: `grepl("MULTNOMAH", LIBNAME)`.
## Caused by warning in `grepl()`:
## ! unable to translate 'COROZAL PUBLIC LIBRARY (TE<d3>FILO MALDONADO RIVERA)' to a wide string
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 15 remaining warnings.
df %>%
  filter(POPU_UND >= benchmark) %>%
  filter(!(TOTCIR %in% c(-1, -3))) %>%
  mutate(circulationPerCapita = TOTCIR / POPU_UND) %>%
  mutate(rankTotalCirculation = rank(-TOTCIR),
         rankCirculationPerCapita = rank(-circulationPerCapita)) %>%
  arrange(rankTotalCirculation) %>%
  select(LIBNAME, starts_with("rank"), TOTCIR, circulationPerCapita, POPU_UND) %>%
  kable()
LIBNAME rankTotalCirculation rankCirculationPerCapita TOTCIR circulationPerCapita POPU_UND
LOS ANGELES PUBLIC LIBRARY 1 23 18874940 4.9416814 3819538
KING COUNTY LIBRARY SYSTEM 2 8 18867572 11.9277994 1581815
CINCINNATI AND HAMILTON COUNTY PUBLIC LIBRARY 3 1 17512491 21.0978108 830062
MULTNOMAH COUNTY LIBRARY 4 2 16506307 20.1131597 820672
HENNEPIN COUNTY LIBRARY 5 5 16204855 13.4253620 1207033
NEW YORK PUBLIC LIBRARY, THE BRANCH LIBRARIES 6 37 13526480 3.7361312 3620451
CHICAGO PUBLIC LIBRARY 7 27 12489095 4.5474620 2746388
SAINT LOUIS COUNTY LIBRARY 8 3 12474280 14.4477402 863407
COLUMBUS METROPOLITAN LIBRARY 9 7 12335654 12.7007367 971255
LA COUNTY LIBRARY 10 38 12135251 3.7072834 3273354
SALT LAKE COUNTY LIBRARY 11 6 11757899 13.0502814 900969
SAN FRANCISCO PUBLIC LIBRARY 12 4 11432696 13.5658757 842754
FAIRFAX COUNTY PUBLIC LIBRARY 13 11 10579040 9.0615013 1167471
WAKE COUNTY PUBLIC LIBRARIES 14 13 9745969 8.4694383 1150722
BROOKLYN PUBLIC LIBRARY 15 39 9695085 3.5847326 2704549
MARICOPA COUNTY LIBRARY DISTRICT OFFICE 16 41 9600053 3.3082390 2901862
HARRIS COUNTY PUBLIC LIBRARY 17 29 9518572 4.3286876 2198951
MONTGOMERY COUNTY PUBLIC LIBRARIES 18 12 9355690 9.0571395 1032963
MID-CONTINENT PUBLIC LIBRARY 19 9 8970731 10.6757306 840292
BALTIMORE COUNTY PUBLIC LIBRARY 20 10 8564872 10.3519248 827370
PHOENIX PUBLIC LIBRARY 21 15 8265178 7.8834909 1048416
HILLSBOROUGH COUNTY PUBLIC LIBRARY COOPERATIVE 22 21 8248213 5.5569716 1484300
SAN DIEGO COUNTY LIBRARY 23 17 8218124 7.3859425 1112671
ORANGE COUNTY PUBLIC LIBRARIES 24 24 8069504 4.8672340 1657924
PALM BEACH COUNTY LIBRARY SYSTEM 25 14 7837583 8.0247688 976674
LAS VEGAS-CLARK COUNTY LIBRARY DISTRICT 26 28 7704567 4.5345843 1699068
SAN ANTONIO PUBLIC LIBRARY 27 30 7548953 4.1607914 1814307
SACRAMENTO PUBLIC LIBRARY 28 25 7260551 4.8662362 1492026
INDIANAPOLIS PUBLIC LIBRARY 29 16 6930303 7.4336424 932289
SAN JOSE PUBLIC LIBRARY 30 18 6904551 7.0708431 976482
AUSTIN PUBLIC LIBRARY 31 19 6747189 6.9978738 964177
BROWARD COUNTY LIBRARIES DIVISION 32 42 6364498 3.2681927 1947406
QUEENS BOROUGH PUBLIC LIBRARY 33 48 6139318 2.5819885 2377748
ORANGE COUNTY LIBRARY DISTRICT 34 32 5986490 4.1229327 1451998
CHARLOTTE MECKLENBURG LIBRARY 35 22 5903088 5.2636493 1121482
CONTRA COSTA COUNTY LIBRARY 36 20 5868146 5.6312614 1042066
FREE LIBRARY OF PHILADELPHIA 37 40 5583263 3.4812779 1603797
SAN DIEGO PUBLIC LIBRARY 38 33 5436363 3.9543225 1374790
DALLAS PUBLIC LIBRARY 39 35 5044638 3.9152552 1288457
PINELLAS PUBLIC LIBRARY COOPERATIVE 40 26 4589030 4.7958360 956878
HAWAII STATE PUBLIC LIBRARY SYSTEM 41 44 4366720 3.0320318 1440196
JACKSONVILLE PUBLIC LIBRARY 42 31 4196132 4.1436526 1012665
MIAMI-DADE PUBLIC LIBRARY SYSTEM 43 51 4056002 1.7138251 2366637
HOUSTON PUBLIC LIBRARY 44 52 3899617 1.7041918 2288250
GWINNETT COUNTY PUBLIC LIBRARY SYSTEM 45 34 3803005 3.9366259 966057
FULTON COUNTY LIBRARY SYSTEM 46 43 3592148 3.2491249 1105574
SAN BERNARDINO COUNTY LIBRARY 47 46 3568931 2.8081233 1270931
FORT WORTH PUBLIC LIBRARY 48 36 3556312 3.8014768 935508
RIVERSIDE COUNTY LIBRARY SYSTEM 49 50 2788928 2.0316461 1372743
PRINCE GEORGE`S COUNTY MEMORIAL LIBRARY SYSTE 50 45 2700157 2.9694015 909327
BUFFALO AND ERIE COUNTY PUBLIC LIBRARY 51 47 2515996 2.6673947 943241
FRESNO COUNTY PUBLIC LIBRARY 52 49 2507087 2.5379844 987826
KERN COUNTY LIBRARY 53 53 784507 0.8821356 889327
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment