Title: | Opinionated Approach for Digitizing Semi-Structured Qualitative GIS Data |
---|---|
Description: | Provides a set of functions for taking qualitative GIS data, hand drawn on a map, and converting it to a simple features object. These tools are focused on data that are drawn on a map that contains some type of polygon features. For each area identified on the map, the id numbers of these polygons can be entered as vectors and transformed using qualmap. |
Authors: | Christopher Prener [aut, cre] |
Maintainer: | Christopher Prener <[email protected]> |
License: | GPL-3 |
Version: | 0.2.2 |
Built: | 2025-01-02 04:12:29 UTC |
Source: | https://github.com/chris-prener/qualmap |
A wrapper around dplyr::bind_rows
for combining cluster objects created with
qm_create
into a single tibble. Input data for qm_combine
are validated using
qm_is_cluster
as part of the cluster object creation process.
qm_combine(...)
qm_combine(...)
... |
A list of cluster objects to be combined. |
A single tibble with all observations from the listed cluster objects. This tibble is
stored with a custom class of qm_cluster
to facilitate data validation.
qm_create
, qm_is_cluster
# load and format reference data stl <- stLouis stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE)) # create clusters cluster1 <- qm_define(118600, 119101, 119300) cluster2 <- qm_define(119300, 121200, 121100) # create cluster objects cluster_obj1 <- qm_create(ref = stl, key = TRACTCE, value = cluster1, rid = 1, cid = 1, category = "positive") cluster_obj2 <- qm_create(ref = stl, key = TRACTCE, value = cluster2, rid = 1, cid = 2, category = "positive") # combine cluster objects clusters <- qm_combine(cluster_obj1, cluster_obj2)
# load and format reference data stl <- stLouis stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE)) # create clusters cluster1 <- qm_define(118600, 119101, 119300) cluster2 <- qm_define(119300, 121200, 121100) # create cluster objects cluster_obj1 <- qm_create(ref = stl, key = TRACTCE, value = cluster1, rid = 1, cid = 1, category = "positive") cluster_obj2 <- qm_create(ref = stl, key = TRACTCE, value = cluster2, rid = 1, cid = 2, category = "positive") # combine cluster objects clusters <- qm_combine(cluster_obj1, cluster_obj2)
Each vector of input values is converted to a tibble organized in a "tidy" fashion.
qm_create(ref, key, value, rid, cid, category, ...)
qm_create(ref, key, value, rid, cid, category, ...)
ref |
An |
key |
Name of geographic id variable in the |
value |
A vector of input values created with |
rid |
Respondent identification number; a user defined integer value that uniquely identifies respondents in the project |
cid |
Cluster identification number; a user defined integer value that uniquely identifies clusters |
category |
Category type; a user defined value that describes what the cluster represents |
... |
An unquoted list of variables from the sf object to include in the output |
A cluster object contains a row for each feature in the reference data set. The key
variable
values are included in a variable named identically to the key
. Three pieces of metadata are also included
as arguments to provide data for subsetting later: a respondent identification number (rid
), a
cluster identification number (cid
), and a category for the cluster type (category
). These
arguments are converted into values for the output variables RID
, CID
, and CAT
respectively.
Input data for qm_create
are validated using qm_validate
as part of the cluster object
creation process.
A tibble with the cluster values merged with elements of the reference data. This tibble is stored with
a custom class of qm_cluster
to facilitate data validation.
qm_define
, qm_validate
# load and format reference data stl <- stLouis stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE)) # create cluster cluster <- qm_define(118600, 119101, 119300) # create simple cluster object cluster_obj1 <- qm_create(ref = stl, key = TRACTCE, value = cluster, rid = 1, cid = 1, category = "positive") # create cluster object with additional variables added from reference data cluster_obj2 <- qm_create(ref = stl, key = TRACTCE, value = cluster, rid = 1, cid = 1, category = "positive", NAME, NAMELSAD)
# load and format reference data stl <- stLouis stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE)) # create cluster cluster <- qm_define(118600, 119101, 119300) # create simple cluster object cluster_obj1 <- qm_create(ref = stl, key = TRACTCE, value = cluster, rid = 1, cid = 1, category = "positive") # create cluster object with additional variables added from reference data cluster_obj2 <- qm_create(ref = stl, key = TRACTCE, value = cluster, rid = 1, cid = 1, category = "positive", NAME, NAMELSAD)
A wrapper around base::c
that is used for constructing vectors of individual feature values.
Each output should correspond to a single cluster on the respondent's map.
qm_define(...)
qm_define(...)
... |
A comma separated list of individual features |
A vector list each feature.
cluster <- qm_define(118600, 119101, 119300)
cluster <- qm_define(118600, 119101, 119300)
This function tests to see whether an object contains the characteristics of an object
created by qm_cluster
. It is used as part of the qm_combine
and qm_summarize
functions, and is exported so that it can be used interactively as well.
qm_is_cluster(obj, verbose = FALSE)
qm_is_cluster(obj, verbose = FALSE)
obj |
Object to test |
verbose |
A logical scalar; if |
A logical scalar that is TRUE
if the given object contains the approprite
characteristics; if it does not, FALSE
is returned.
qm_combine
, qm_summarize
# load and format reference data stl <- stLouis stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE)) # create cluster cluster <- qm_define(118600, 119101, 119300) # create simple cluster object cluster_obj <- qm_create(ref = stl, key = TRACTCE, value = cluster, rid = 1, cid = 1, category = "positive") # test cluster object qm_is_cluster(cluster_obj) qm_is_cluster(cluster_obj, verbose = TRUE)
# load and format reference data stl <- stLouis stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE)) # create cluster cluster <- qm_define(118600, 119101, 119300) # create simple cluster object cluster_obj <- qm_create(ref = stl, key = TRACTCE, value = cluster, rid = 1, cid = 1, category = "positive") # test cluster object qm_is_cluster(cluster_obj) qm_is_cluster(cluster_obj, verbose = TRUE)
This function renders the input vector as a polygon shapefile using the leaflet package.
qm_preview(ref, key, value)
qm_preview(ref, key, value)
ref |
An |
key |
Name of geographic id variable in the |
value |
A vector of input values created with |
An interactive leaflet map with the features from the defined vector specified in value
highlighted in red.
qm_define
## Not run: # load and format reference data stl <- stLouis stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE)) # create cluster cluster <- qm_define(118600, 119101, 119300) # preview cluster qm_preview(ref = stl, key = TRACTCE, value = cluster) ## End(Not run)
## Not run: # load and format reference data stl <- stLouis stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE)) # create cluster cluster <- qm_define(118600, 119101, 119300) # preview cluster qm_preview(ref = stl, key = TRACTCE, value = cluster) ## End(Not run)
This function creates a column that contains a single observation for each unique value in the key variable. For each feature, a count corresponding to the number of times that feature is identified in a cluster for the give category is also provided.
qm_summarize(ref, key, clusters, category, count, geometry = TRUE, use.na = FALSE)
qm_summarize(ref, key, clusters, category, count, geometry = TRUE, use.na = FALSE)
ref |
An |
key |
Name of geographic id variable in the |
clusters |
A tibble created by |
category |
Value of the |
count |
How should clusters be summarized: by counting each time a feature is included
in a cluster ( |
geometry |
A logical scalar that returns the full geometry and attributes of |
use.na |
A logical scalar that returns |
A tibble or a sf
object (if geometry = TRUE
) that contains a count of the number
of clusters a given feature is included in. The tibble option (when geometry = FALSE
) will only
return valid features. The sf
option (default; when geometry = TRUE
) will return all
features with either zeros (when use.na = FALSE
) or NA
values (when use.na = TRUE
)
for features not included in any clusters.
qm_combine
# load and format reference data stl <- stLouis stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE)) # create clusters cluster1 <- qm_define(118600, 119101, 119300) cluster2 <- qm_define(119300, 121200, 121100) # create cluster objects cluster_obj1 <- qm_create(ref = stl, key = TRACTCE, value = cluster1, rid = 1, cid = 1, category = "positive") cluster_obj2 <- qm_create(ref = stl, key = TRACTCE, value = cluster2, rid = 1, cid = 2, category = "positive") # combine cluster objects clusters <- qm_combine(cluster_obj1, cluster_obj2) # summarize cluster objects positive1 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", count = "clusters") class(positive1) mean(positive1$positive) # summarize cluster objects with NA's instead of 0's positive2 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", count = "clusters", use.na = TRUE) class(positive2) mean(positive2$positive, na.rm = TRUE) # return tibble of valid features only positive3 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", count = "clusters", geometry = FALSE) class(positive3) mean(positive3$positive) # count respondents instead of clusters positive4 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", count = "respondents") mean(positive4$positive)
# load and format reference data stl <- stLouis stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE)) # create clusters cluster1 <- qm_define(118600, 119101, 119300) cluster2 <- qm_define(119300, 121200, 121100) # create cluster objects cluster_obj1 <- qm_create(ref = stl, key = TRACTCE, value = cluster1, rid = 1, cid = 1, category = "positive") cluster_obj2 <- qm_create(ref = stl, key = TRACTCE, value = cluster2, rid = 1, cid = 2, category = "positive") # combine cluster objects clusters <- qm_combine(cluster_obj1, cluster_obj2) # summarize cluster objects positive1 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", count = "clusters") class(positive1) mean(positive1$positive) # summarize cluster objects with NA's instead of 0's positive2 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", count = "clusters", use.na = TRUE) class(positive2) mean(positive2$positive, na.rm = TRUE) # return tibble of valid features only positive3 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", count = "clusters", geometry = FALSE) class(positive3) mean(positive3$positive) # count respondents instead of clusters positive4 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", count = "respondents") mean(positive4$positive)
This function ensures that the input vector values match valid values in a source shapefile.
qm_validate(ref, key, value)
qm_validate(ref, key, value)
ref |
An |
key |
Name of geographic id variable in the |
value |
A vector of input values created with |
A logical scalar that is TRUE
is all input values match values in the key variable.
qm_define
# load and format reference data stl <- stLouis stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE)) # create clusters clusterValid <- qm_define(118600, 119101, 119300) clusterError <- qm_define(118600, 119101, 800000) # validate clusters qm_validate(ref = stl, key = TRACTCE, value = clusterValid) qm_validate(ref = stl, key = TRACTCE, value = clusterError)
# load and format reference data stl <- stLouis stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE)) # create clusters clusterValid <- qm_define(118600, 119101, 119300) clusterError <- qm_define(118600, 119101, 800000) # validate clusters qm_validate(ref = stl, key = TRACTCE, value = clusterValid) qm_validate(ref = stl, key = TRACTCE, value = clusterError)
Users may wish to save long-form combined cluster data as a .csv
file
or similar after combining individual clusters with qm_combine
. The qm_verify
function allows users to import data from any file type readable by R
, and verify that it
has the column names needed for qm_summarize
.
qm_verify(clusters)
qm_verify(clusters)
clusters |
An object created by |
A tibble stored with a custom class of qm_cluster
to facilitate data validation.
A simple features data set containing the geometry and associated attributes for the 2016 City of St. Louis census tracts.
data(stLouis)
data(stLouis)
A data frame with 106 rows and 7 variables:
state FIPS code
county FIPS code
tract FIPS code
full GEOID string
tract FIPS code, decimal
tract name
simple features geometry
These data have been modified from the full version available from the Census Bureau - some variables related to geometry and geography type have been removed.
#' @examples str(stLouis) head(stLouis)