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

Roger Bivand Roger.Bivand at nhh.no
Wed Jul 2 09:53:04 CEST 2014


As with polygon, use the border= argument.

Roger

On Wed, 2 Jul 2014, Spencer Graves wrote:

> 	  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:
>> An example:
>> 
>> library(raster)
>> ct <- getData("countries")
>> plot(subset(ct, NAME %in% c("Azerbaijan", "Uzbekistan", "Tajikistan",
>> "Turkmenistan", "Croatia"))
>> 
>> 
>> 
>> 
>> On Wed, Jul 2, 2014 at 9:09 AM, Michael Sumner <mdsumner at gmail.com> wrote:
>> 
>>> 
>>> On Wed, Jul 2, 2014 at 7:56 AM, Thomas Adams <tea3rd at gmail.com> wrote:
>>> 
>>>> Spencer,
>>>> 
>>>> Maybe I'm not sure what you're asking but here
>>>> http://www.gadm.org/version1
>>>> are current shapefiles by country. The highlighting (selection) canals 
>>>> be
>>>> done in GRASS GIS, QGIS, GMT
>>>> 
>>>>
>>>   raster::getData can read this. See here http://www.gadm.org/ and
>>> 
>>> library(raster)
>>> ?getData
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>>> Tom
>>>> 
>>>> 
>>>> On Tue, Jul 1, 2014 at 2:29 PM, Spencer Graves <
>>>> spencer.graves at prodsyse.com>
>>>> wrote:
>>>>
>>>>>        What would you suggest I do to create a world map highlighting
>>>>> Taiwan and post-Soviet states like Azerbaijan, Uzbekistan, Tajikistan,
>>>>> Turkmenistan, and Croatia?
>>>>> 
>>>>>
>>>>>        The region argument in maps::map won't recognize any of these, 
>>>>> and
>>>>> my literature search identified hundreds of packages with some spatial /
>>>>> geographical / mapping content.
>>>>> 
>>>>>
>>>>>        Thanks,
>>>>>        Spencer Graves
>>>>> 
>>>>> _______________________________________________
>>>>> R-sig-Geo mailing list
>>>>> R-sig-Geo at r-project.org
>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>> 
>>>> 
>>>> --
>>>> Michael Sumner
>>>> Software and Database Engineer
>>>> Australian Antarctic Division
>>>> Hobart, Australia
>>>> e-mail: mdsumner at gmail.com
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list