I would like to create a choropleth map using leafletR::leaflet
.
My data comes in a SpatialPolygonsDataFrame
, and I would like to choose a specific column to be plotted.
With sp::spplot
, this is easy-peasy, since the argument zcol
allows me to specify the layer/column to be plotted:
library("maptools");library("sp");library("leafletR")
SP <- readShapePoly(system.file("shapes/sids.shp",
package="maptools")[1],
proj4string=CRS("+proj=longlat +datum=WGS84
+no_defs +ellps=WGS84
+towgs84=0,0,0"))
spplot(SP, zcol="BIR79")
However, with leafletR
, I don't know how to specify the layer, and it just plots the plain map borders:
SP4leaflet <- toGeoJSON(data=SP, dest=tempdir(), name="BIR79")
SPleaflet <- leaflet(data=SP4leaflet, dest=tempdir(),
title="Trying to plot BIR79",
base.map="osm", popup="*")
SPleaflet
Any ideas on how to select the desired layer/column to be plotted with leafletR
?