Introduction to LeafletMegan KressSeptember 12, 2016
What Is Leaflet?Leaflet is an open-source JavaScript library found at http://leafletjs.com/. Its purpose is to embed R code in your webpage to produce interactive maps.
Leaflet Example
Install LeafletLeaflet is available as a package on CRAN (https://cran.r-project.org/web/packages/leaflet/index.html), so it can easily be downloaded from the command line in RStudio:
Simple Map Using Leaflet
See the Shiny app version of this R code here.
Note: The “%>%” symbol is a magrittr pipe operator (http://blog.revolutionanalytics.com/2014/07/magrittr-simplifying-r-code-with-pipes.html). The code below is equivalent to the above code and does not use pipes.
0 Comments
Using MAPZEN data and the LeafletR package to create a Leaflet map in RRyan NagelkirkData Category: Mapping tools Data Description: MAPZEN is a cool website that has freely available GIS data for metro areas; country, region and city boundaries; and descriptions of different places (found in Who’s On First). MAPZEN uses the geojson data format, which allows you to map the files to an interactive map on the internet (Leaflet map, in this case) using the leafletR package. Here, I’ll map Australia. I will admit to not knowing how to use a Leaflet map to its full utility, but Leaflet maps allow users to click on parts of your map to interact with the data you have saved to different features on the map. The code below simply plots Australia on the map. Website: https://mapzen.com/ Data Use Policy: https://mapzen.com/terms/ Instructions First download the Australia border file from mapzen.com: https://mapzen.com/data/borders/. You’ll need to click on Australia and then the “GEOJSON” button with the file size written below it. We’ll just use the regions.geojson file here. Load packages:
Create the map:
A map similar to the one below will be created in the html file (but you’ll be able to see the whole world and zoom in and out). |
Spatial Ecology @ MSUClick on "Category" below to search for R code compiled by the Zarnetske Spatial & Community Ecology Lab and students in MSU's Spatial Ecology graduate course (FOR870/FW870) Category
All
Archive
October 2016
|