Scalebars and North Arrows with MapmiscSeptember 21, 2016Description: The package mapmisc is great for creating simple, fast, and effective maps; it utilizes shorter, neater coding at the cost of being less customizable than some other mapping packages. This R-Tip is modified from: https://cran.r-project.org/web/packages/mapmisc/vignettes/mapmisc.pdf First, let’s install and load some packages that we’ll be using in this R-Tip, including the mapmisc package.
Let’s download regional shapefiles for the US. You can download the file cb_2014_us_region_20m.shp from this website: http://www2.census.gov/geo/tiger/GENZ2014/shp/ Let’s open the shapefiles in R and read them in:
Next, we’ll define the shapefile’s projection, and since we’re dealing with a map of the US, we’ll reproject the shapefile using the US National Atlas equal-area projection.
Now, we can add a scaleBar and north arrow easily with mapmisc. scaleBar() is particularly user-friendly because it automatically generates the scale and true north based on the projection settings of the object you provide.
In the map above, we can see scaleBar seems to have taken one of the extremes for the north arrow; as I mentioned at the beginning, mapmisc is user friendly, but it does take away some options to customize your map, and with such a large extent being mapped, this north arrow may not be ideal. For fun, let’s try that again, this time with just the northeast. The north arrow will be able to represent true north better for a smaller area.
scaleBar is a very user-friendly command from the package mapmisc that can help you easily enhance your maps. Keep in mind some of the shortcomings discussed when choosing to use this command.
0 Comments
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.
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
|
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
|