Skip to content
Prev 21256 / 29559 Next

line color in plot(SpatialPolygonsDataFrame) [was: maps showing post-Soviet states?]

How can one control the color of lines with 
plot(SpatialPolygonsDataFrame)?


	  Adding lwd=9 to the arguments for plot produces black borders so wide 
most of the red disappears:


map(xlim=c(10, 90), ylim=c(30, 60))
library(raster)
ct <- getData("countries")
plot(subset(ct, NAME %in% c("Azerbaijan", "Uzbekistan", "Tajikistan",
                             "Turkmenistan", "Croatia")),
             add=TRUE, col='red', lwd=9)


	  A related question is how can I see the plot function used here? 
Methods dispatch does not take this to plot.default nor to 
plot.SpatialPolygonsDataFrame, as it would with an S3 method.


	  Thanks,
	  Spencer


#########################
       Thanks to Gilles Leduc, Greg Snow, Thomas Adams, Barry 
Rowlingson, and Michael Sumner for their replies.  For the archives, in 
case someone else might find this in the archives, I will record here 
two solutions to my problem.


       1.  Michael's reply was the simplest, especially since it worked 
with "map" adding "add=TRUE" and "col" to the plot:

map(xlim=c(10, 90), ylim=c(30, 60))
library(raster)
ct <- getData("countries")
plot(subset(ct, NAME %in% c("Azerbaijan", "Uzbekistan", "Tajikistan",
                             "Turkmenistan", "Croatia")),
             add=TRUE, col='red')


       2.  Before I saw Michael's reply, I had solved the problem with 
much greater effort:  (1) I downloaded a zip file for each country from 
"www.diva-gis.org/datadown", as suggested by Gilles. (2) Unzipping 
produced folders with names like "..\TWN_adm" and files with names 
beginning "TWN_adm0", "TWN_adm1", and "TWN_adm2" and extensions bdf, 
prj, sbn, sbx, shp, and shx.  I could then get what I wanted with code 
like the following:


Taiwan0 <- readShapeSpatial("..\TWN_adm0")
map(xlim=c(100, 150), ylim=c(10, 30))
plot(Taiwan0, add=TRUE, col='blue', lwd=3, fill=FALSE)


       Again, thanks for the replies.
On 7/1/2014 4:38 PM, Michael Sumner wrote: