[R] Coloring counties on a full US map based on a certain criterion

Sarah Goslee sarah.goslee at gmail.com
Fri Jan 13 20:04:04 CET 2012


On Fri, Jan 13, 2012 at 1:52 PM, Dimitri Liakhovitski
<dimitri.liakhovitski at gmail.com> wrote:
> Just to clarify, according to help about the "fill" argument:
> logical flag that says whether to draw lines or fill areas. If FALSE,
> the lines bounding each region will be drawn (but only once, for
> interior lines). If TRUE, each region will be filled using colors from
> the col = argument, and bounding lines will not be drawn.
> We have fill=TRUE - so why are the county borders still drawn?
> Thank you!
> Dimitri
>

This prompted me to check the code:

if fill=TRUE, map() calls polygon()
if fill=FALSE, map() calls lines()

But polygon() draws borders by default.
> plot(c(0,1), c(0,1), type="n")
> polygon(c(0,0,1,1), c(0,1,1,0), col="yellow")

To not draw borders, the border argument is provided:
> plot(c(0,1), c(0,1), type="n")
> polygon(c(0,0,1,1), c(0,1,1,0), col="yellow", border=NA)

But that fails in map():
> map('county', 'iowa', fill=TRUE, col=rainbow(20), border=NA)
Error in par(pin = p) :
  invalid value specified for graphical parameter "pin"

because border is used as a named argument in map() already, for setting the
size of the plot area, so there's no way to alter the border argument
to polygon.

The work-around I suggested previous (lty=0) seems to be the only
way to deal with the problem.

Sarah



More information about the R-help mailing list