Getting Started with Cincinnati Open Data

Shelby Lyn Gomes

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  warning = FALSE,
  message = FALSE
)
library(cincinnatiOpenData)
library(dplyr)
library(ggplot2)

Introduction

Welcome to the cincinnatiOpenData package, an R package designed to provide convenient access to the Cincinnati Open Data Portal.

The package provides a streamlined interface for discovering and downloading datasets from Cincinnati Open Data. It helps bridge the gap between raw Socrata API endpoints and tidy data analysis in R.

The package provides three primary functions:

Listing Available Datasets

The first step in a typical workflow is to use cincinnati_list_datasets() to retrieve the live Cincinnati Open Data catalog.

catalog <- cincinnati_list_datasets()

catalog

The returned catalog includes information about the datasets available through the portal. Two especially important columns are:

You can search the catalog for datasets containing a keyword.

catalog |>
  filter(grepl("business", name, ignore.case = TRUE)) |>
  select(key, uid, name)

Replace KEYWORD with a useful search term related to the example dataset selected for the package.

Pulling a Dataset

The primary way to download data is with cincinnati_pull_dataset().

A dataset can be requested using either its human-readable catalog key or its official Socrata UID.

Pulling by UID

example_data_uid <- cincinnati_pull_dataset(
  dataset = "7dk3-gngs",
  limit = 5
)

example_data_uid

Pulling by Key

example_data_key <- cincinnati_pull_dataset(
  dataset = "business_licenses",
  limit = 5
)

example_data_key

Both calls should return data from the same dataset.

Keys and UIDs

Dataset keys are easier to read, while Socrata UIDs are more stable.

For reproducible research and long-term workflows, using the official Socrata UID is generally recommended.

Filtering Data

The filters argument can be used for simple exact-match filtering.

filtered_data <- cincinnati_pull_dataset(
  dataset = "7dk3-gngs",
  limit = 25,
  filters = list(
    license = "GAME ARCADE"
  )
)

filtered_data

You can confirm that the filter worked by inspecting the unique values in the selected field.

filtered_data |>
  distinct(license)

Multiple values can also be supplied.

filtered_multiple <- cincinnati_pull_dataset(
  dataset = "7dk3-gngs",
  limit = 50,
  filters = list(
    license = c("GAME ARCADE", "AMUSEMENT GAME EXHIBITOR")
  )
)

filtered_multiple

Multiple fields can be combined within the same filter list.

filtered_combination <- cincinnati_pull_dataset(
  dataset = "7dk3-gngs",
  limit = 50,
  filters = list(
    license = "GAME ARCADE",
    neighborhood = "ROSELAWN"
  )
)

filtered_combination

Filtering by Date

If the example dataset contains a date or datetime field, records can be filtered using from, to, and date_field.

date_filtered_data <- cincinnati_pull_dataset(
  dataset = "7dk3-gngs",
  from = "2004-01-01",
  to = "2005-01-01",
  date_field = "effectivefrom",
  limit = 100
)

date_filtered_data

The from date is inclusive, while the to date is exclusive.

A single day can also be requested using the date argument.

single_day_data <- cincinnati_pull_dataset(
  dataset = "7dk3-gngs",
  date = "2004-01-01",
  date_field = "effectivefrom",
  limit = 100
)

single_day_data

Pulling Data from Any Socrata Endpoint

The preferred workflow is to use cincinnati_list_datasets() together with cincinnati_pull_dataset().

However, when a dataset is not available in the package catalog, cincinnati_any_dataset() can download data directly from a Socrata JSON endpoint.

Cincinnati Open Data endpoints typically follow this structure:

https://data.cincinnati-oh.gov/resource/<dataset_uid>.json

For example:

https://data.cincinnati-oh.gov/resource/7dk3-gngs.json

The endpoint can then be supplied directly to cincinnati_any_dataset().

endpoint_data <- cincinnati_any_dataset(
  json_link = "https://data.cincinnati-oh.gov/resource/7dk3-gngs.json",
  limit = 5
)

endpoint_data

Which function should you use?

Use cincinnati_pull_dataset() when the dataset is available through cincinnati_list_datasets().

Use cincinnati_any_dataset() when you already have a valid Socrata JSON endpoint or when the dataset is not included in the package catalog.

Example Analysis

Once the data have been downloaded, they can be analyzed using standard R tools.

The following example counts the number of records in a categorical field.

category_summary <- cincinnati_pull_dataset(
  dataset = "7dk3-gngs",
  limit = 500
) |>
  filter(!is.na(license)) |>
  count(license, sort = TRUE)

category_summary

The results can then be visualized.

category_summary |>
  slice_head(n = 10) |>
  ggplot(
    aes(
      x = n,
      y = reorder(license, n)
    )
  ) +
  geom_col() +
  theme_minimal() +
  labs(
    title = "Most Frequent Categories",
    x = "Number of Records",
    y = "License"
  )

This example demonstrates the complete workflow from discovering a dataset to downloading, filtering, summarizing, and visualizing it.

Summary

The cincinnatiOpenData package provides a consistent interface for working with data from the Cincinnati Open Data Portal.

In this vignette, you learned how to:

These functions allow users to focus on analysis rather than manually constructing API requests.

How to Cite

If you use this package for research or educational purposes, cite it using the package citation returned by:

citation("cincinnatiOpenData")