getGeoDataFrame: Get a CrunchDataFrame inside of a SpatialDataFrame

Description Usage Arguments Value Examples

View source: R/crunchgeo.R

Description

The sp package has a number of classes of SpatialXDataFrames like SpatialPolygonDataFrame. These include both data.frame content (in their @data slot) as well as the spatial information (polygons, points, etc.; in their @polygons, @points, etc. slots). This function replaces the data.frame that would normally come from the topo- or geo-json with a CrunchDataFrame that includes all of the same information as the original data.frame, but also with information about the CrunchDataSet (similar to using as.data.frame(dataset)).

Usage

1

Arguments

geo_var

the alias of the variable that has geodata associated with it

data

a Crunch dataset object

...

passed to fetchGeoFile

Value

a SpatialDataFrame with a CrunchDataFrame in the Data slot instead of a standard data.frame

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
library(leaflet)
ds_geodata <- getGeoDataFrame("state", ds)

# a very simple leaflet choropleth
pal <- colorNumeric(
palette = "viridis",
domain = ds_geodata$turnout)

leaflet(ds_geodata) %>%
    addPolygons(color = "#444444", weight = 0.5, smoothFactor = 0.5,
                opacity = 0.75, fillOpacity = 0.85,
                fillColor = ~pal(turnout))

## End(Not run)

Crunch-io/crunchgeo documentation built on May 6, 2019, 10:52 p.m.