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.
Lab9S ShafferNovember 12, 2015Lab 9 ***************************************************************************************R Trick/Snippet How to color a polygon and change border thickness For color changes, see: http://gis.stackexchange.com/questions/36877/how-do-i-change-the-polygon-fill-color-and-border-color-for-spatialpolygons-obje For border thickness, see: http://stackoverflow.com/questions/18994051/how-to-set-line-width-and-color-when-plotting-a-shapefile-with-plot Install packages (i.e., these are only needed for downloading the data in this example):
Download polygon data. In this case, the polygon I will use is a US state border.
Plot a polygon
Replot the polygon, but with color and with different border thickness. col=“[name of color]” changes the interior. border=“[name of color]” changes the border color. lwd=[#] changes the border thickness. (For lwd, the default is 1.)
|
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
|