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

Sarah Goslee sarah.goslee at gmail.com
Fri Jan 13 21:19:55 CET 2012


Changing the color of the borders is what the border argument to
polygon() would do, if only it hadn't been overridden.

So no, you can't easily change the line color. It would be an easy
tweak to the code to add a polyborder argument that is passed
to polygon() as border, though. That would solve both your
problems.

Sarah

On Fri, Jan 13, 2012 at 3:13 PM, Dimitri Liakhovitski
<dimitri.liakhovitski at gmail.com> wrote:
>>
>> But the help does say that additional arguments are passed to lines(),
>> so you can use lty=0.
>>
>> That can leave white bits between counties if the areas don't line up
>> precisely, so I think it looks better with the lines in black.
>
> I agree, indeed it leaves white bits. Of course, I could try to change
> the type of the lines using lty...
> Sorry for one more question: can one change the color of these lines
> (borders between counties) from black?
> Thank you!
> D.
>
>
>>
>> Sarah
>>
>>> Thank you!
>>> Dimitri
>>>
>>> ### My criterion for all counties.:
>>> allcounties<-data.frame(county=map('county', plot=FALSE)$names)
>>> allcounties$group<-c(rep(1:6,513),rep(1,4))[order(c(rep(1:6,513),rep(1,4)))]
>>> ### My colors:
>>> classcolors <- rainbow(6)
>>> map('county',fill=TRUE,col=classcolors[allcounties$group])
>>> map('state', lwd=2, add=TRUE)
>>>
>>>
>>>
>>>> Sure. Just start with
>>>> map('county')
>>>> instead.
>>>> I like to add something like:
>>>> map('state', lwd=3, add=TRUE)
>>>
>>> I am trying:
>>> ### My criterion for all counties in the US:
>>> allcounties<-data.frame(county=map('county', plot=FALSE)$names)
>>> allcounties$group<-sample(1:5,3082,replace=TRUE)
>>> ### My colors:
>>> classcolors <- rainbow(5)
>>> ### Trying to build the map - not working:
>>> map(database='usa',regions='county',fill=TRUE,col=classcolors[allcounties$group])
>>>
>>>
>>>
>>>> You'll need to instead coordinate with the names of the entire US:
>>>>> length(map('county', plot=FALSE)$names)
>>>> [1] 3082
>>>>
>>>> Sarah
>>>>



More information about the R-help mailing list