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.)
Easy Access to Maps for Spatial WorkInstead of searching the internet for a shapefile for a state or country that you are wanting to work on you can use the package maps. The package maps contains the outline for US cities, US counties, states, and countries. You first need to install the maps package. There are numerous parts to this package. Here’s an example:
First we’ll start with a Michigan outline.
If you’re looking for an outline of the USA, you can do this:
Remember, you can always fill the object in with a color using col= If you wanted to have the whole country with the states also you can use:
These are just a few of the maps you can easily get using this package. |
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
|