[R] map at fips level using multiple variables

Greg Snow Greg.Snow at imail.org
Wed Dec 14 18:41:48 CET 2011


Colors probably are not the best for so many levels and combinations.  Look at the symbols function (or the my.symbols and subplot functions in the TeachingDemos package) for ways to add symbols to a map showing multiple variables.

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of bby2103 at columbia.edu
Sent: Wednesday, December 07, 2011 9:14 PM
To: David Winsemius
Cc: r-help at r-project.org
Subject: Re: [R] map at fips level using multiple variables

Hi David,

Sorry it sounds vague.

Here is my current code, which gives the distribution of family size  
at US county level. You will see on a US map family size distribution  
represented by different colors.

Now if i have another variable income, which has 3 categories(<50k,  
50k-80k,>80k). How do I show 5x3 categories on the map? I guess I  
could always create a third variable to do this. Just wondering maybe  
there is a function to do this readily?

Thank you!
Bonnie Yuan

y=data1$size
x11()
hist(y,nclass=15) # histogram of y
fivenum(y)
# specify the cut-off point of y
y.colorBuckets=as.numeric(cut(y, c(1,2, 3,6)))
# legend showing the cut-off points.
legend.txt=c("0-1","1-2","2-3","3-6",">6")
colorsmatched=y.colorBuckets[match(county.fips$fips,fips[,1])]
x11()
map("county", col = colors[colorsmatched], fill = TRUE, resolution = 0)
map("state", col = "white", fill = FALSE, add = TRUE, lty = 1, lwd = 0.2)
title("Family Size")
legend("bottom", legend.txt, horiz = TRUE, fill = colors, cex=0.7)



Quoting David Winsemius <dwinsemius at comcast.net>:

>
> On Dec 7, 2011, at 6:12 PM, bby2103 at columbia.edu wrote:
>
>> Hi, I just started playing with county FIPS feature in maps package  
>>  which allows geospatial visualization of variables on US county   
>> level. Pretty cool.
>
> Got code?
>
>>
>> I did some search but couldn't find answer to this question--how   
>> can I map more than 2 variables on US map?
>
> "2 variables" is a bit on the vague side for programming purposes.
>
>> For example, you can map by the breakdown of income or family size.  
>>  How do you further breakdown based on the values of both variables  
>>  and show them on the county FIPS level?
>
> "breakdown" suggests a factor construct. If so, then :
>
> ?interaction
>
> But the "show" part of the question remains very vague.
>
>  Can't you be a bit more specific? What DO you want?
>
> -- 
> David Winsemius, MD
> West Hartford, CT

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list