Re: [R] images and maps in R

From: Roger Bivand <Roger.Bivand_at_nhh.no>
Date: Sat 28 May 2005 - 23:27:44 EST


On Fri, 27 May 2005, Don MacQueen wrote:

> This is is not difficult from the online help for the map() function.
> Here is an example.
>
> map('state', region = c('new york', 'new jersey', 'penn'),fill=TRUE,col=1:4)
>
> There is also an example there in how to add text to the map.
>
> Another way uses the maptools package.
>
> require(maptools)
> ?plot.Map
>
> and then follow the examples given in the help page for plot.Map().

Both for map() in the maps package and plot.Map() and plot.polylist() in the maptools package, there are three things to sort out. Firstly, are the map polygons the same, and in the same order as the data you want to map? Next, which palette of colours do you want to use (the RColorBrewer palettes are well-chosen)? And finally, which breakpoints will you use for the class intervals to divide the data into colours?

If the breakpoints are brks:

cols <- brewer.pal(length(brks)-1, "your choice of palette) col_choices <- findInterval(data, brks, all.inside=TRUE)

and your data are the same length and in the same order as the polygons, thematic maps are not too difficult.

>
> At 2:42 PM -0700 5/27/05, yyan liu wrote:
> >Hi:
> > I have a question arising from my project.
> > A sample of the data is below. The first row stands
> >for the names of state in USA. The second row stand
> >for some numeric value in that state. Some of them are
> >NA. I can use the commands "data(stateMapEnv)" and
> >"map('state', fill = F)" in library "maps" to make a
> >plot of USA states. What I want to do is: 1. put the
> >corresponding state name on the Map 2. give different
> >state different colors which is related to their
> >value. For example, "red" for values ranging from
> >0-30, "green" for values from 80-90, etc. 3. if
> >possible, put the value of each state within the state
> >on the map. here, take the numeric value as some text.
> >
> >Thank you very much!
> >
> >AB AK AL AR AZ CT CA
> >91 80 NA NA 17 33 20
> >
> >______________________________________________
> >R-help@stat.math.ethz.ch mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand@nhh.no

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat May 28 23:37:15 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:13 EST