Creating a scale bar for a mapLaura TwardochlebSeptember 21, 2016Here I have modified a function to create a scale bar for a map. I will use an example map of black bear occurrences in the northeastern United States. The original code for the scale bar function was written by eipi10 at http://stackoverflow.com/questions/23784943/how-to-add-a-scale-bar-in-r
I will create the map of the northeast region and plot black bear occurrence data from GBIF (Global Biodiversity Information Facility) using the ‘raster’ library.
The above code produced a map with 100 km x 100 km resolution of bear occurrence data. Now I will add a custom scale bar illustrating 100 km on the map.
0 Comments
Clipping Points to a Raster (extract {raster})Megan KressSeptember 21, 2016
extract FunctionThe extract function extracts data from a Raster object based on the location of another set of spatial data (SpatialPoints, two-column data.frame, SpatialPolygons, etc.). The function comes from the raster package. For more information on the extract function, see the CRAN page for the raster package. For this example, I followed the general structure of Lab 02 (getting species occurrences from GBIF). I used data for the black bear, and clipped it to the outline of the Northeast region.
Preparation (from Lab 02)
Plot All Occurences
Plot Clipped Occurences
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.
|
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
|