Overview

This package implements a process for converting qualitative GIS data from an exercise where respondents are asked to identify salient locations on a map. This article focuses primarily on the use of the software to digitize these data.

Getting Started with R

If you are new to R, welcome! You will need to download R. You are also strongly encouraged to download and use RStudio. macOS users should also download and install XQuartz.

Dependencies

You should check the sf package website for the latest details on installing dependencies for that package. Instructions vary significantly by operating system. For best results, have sf installed before you install qualmap. Other dependencies, like dplyr and leaflet, will be installed automatically with qualmap if they are not already present.

Installation

Once you have those installed, you can install qualmap using the remotes package:

Basics

qualmap is built around a number of fundamental principles. The primary data objects created by qm_combine() are long data rather than wide. This is done to facilitate easy, consistent data management. The package also implements simple features objects using the sf package. This provides a modern interface for working with spatial data in R.

Core Verbs

qualmap implements six core verbs for working with mental map data:

  1. qm_define() - create a vector of feature id numbers that constitute a single “cluster”
  2. qm_validate() - check feature id numbers against a reference data set to ensure that the values are valid
  3. qm_preview() - plot cluster on an interactive map to ensure the feature ids have been entered correctly (the preview should match the map used as a data collection instrument)
  4. qm_create() - create a single cluster object once the data have been validated and visually inspected
  5. qm_combine() - combine multiple cluster objects together into a single tibble data object
  6. qm_summarize() - summarize the combined data object based on a single qualitative construct to prepare for mapping

The order that these functions are listed here is the approximate order in which they should be utilized. Data should be defined, validated and previewed, and then cluster objects should be created, combined, and summarized.

Main Arguments

All of the main functions except qm_define() and qm_combine() rely on two key arguments:

  • ref - a reference object. This should be an sf object that contains a master list of features that appear in your study. This could a sf object representing all census tracts in a city or county, for example, or a tessellated grid covering the extent of a city.
  • key - the name of geographic id variable in the ref object to match input values to. This could be a FIPS code, the GEOID variable in most census data, or the OBJECTID of a tessellated grid. Values entered into qm_define() should key values.

Additionally, a number of the initial functions have a third essential argument:

  • value - the name of the cluster created using qm_define()

Data Preparation

To begin, you will need a simple features object containing the polygons you will be matching respondents’ data to. Census geography polygons can be downloaded via tigris, and other polygon shapefiles can be read into R using the sf package.

Here is an example of preparing data downloaded via tigris:

We download the census tract data for St. Louis, which come in sp format, using the tracts() function from tigris. We then use the sf package’s st_as_sf() function to convert these data to a simple features object and convert the TRACTCE variable to numeric format.

If you want to use your own base data instead, you can use the st_read() function from sf to bring them into R.

Data Entry

Once we have a reference data set constructed, we can begin entering the tract numbers that constitute a single circle on the map or “cluster”. We use the qm_define() function to input these id numbers into a vector:

We can then use the qm_validate() function to check each value in the vector and ensure that these values all match the key variable in the reference data:

If qm_validate() returns a TRUE value, all data are matches. If it returns FALSE, at least one of the input values does not match any of the key variable values. In this case, our key is the TRACTCE variable in the sf object we created earlier.

Once the data are validated, we can preview them interactively using qm_preview(), which will show the features identified in the given vector in red on the map:

Create Cluster Object

A cluster object is tibble data frame that is “tidy” - each feature in the reference data is a row. Cluster objects also contain metadata about the cluster itself: the respondent’s identification number from the study, a cluster identification number, and a category that describes what the cluster represents. Clusters are created using qm_create():

Combine and Summarize Multiple Clusters

Once several cluster objects have been created, they can be combined using qm_combine() to produce a tidy tibble formatted data object:

Since the same census tract appears in multiple rows as part of different clusters, we need to summarize these data before we can map them. Part of qualmap’s opinionated approach revolves around clusters representing only one construct. When we summarize, therefore, we also subset our data so that they represent only one phenomenon. In the above example, there are both “positive” and “negative” clusters. We can use qm_summarize() to extract only the “positive” clusters and then summarize them so that we have one row per census tract:

The qm_summarize() function has an options to return NA values instead of 0 values for features not included in any clusters (when use.na = TRUE), and can return a non-sf tibble of valid features instead of the sf object (when geometry = FALSE).

Mapping Summarized Data

Finally, we can use the geom_sf() geom from ggplot2 to map our summarized data, highlighting areas most discussed as being “positive” parts of St. Louis in our hypothetical study:

library(ggplot2)
library(viridis)

ggplot() + 
  geom_sf(data = qualData, mapping = aes(fill = positive)) + 
  scale_fill_viridis()

Since qualmap output are sf objects, they will work with any of the spatial packages that also support sf.