[19184] in s-news-athena

home help back first fref pref prev next nref lref last post

[S] Summary: map() function

daemon@ATHENA.MIT.EDU (Kieran Healy)
Fri Sep 10 20:32:23 1999

Message-Id: <37D9A1D0.53D6E91C@princeton.edu>
Date: Fri, 10 Sep 1999 20:26:56 -0400
From: Kieran Healy <kjhealy@princeton.edu>
Mime-Version: 1.0
To: S-List <s-news@wubios.wustl.edu>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


Thanks to Doug Johnson and Greg Snow of Mathsoft, and Stephen Kaluzny
for their quick
and informative responses. The short answers are, (1) The map function
is available but it's a library, so must be called with library(maps)
before it can be used. (2) map may print to the graphics device
incorrectly, so (a) you must set the color.table through the graphics
device first, and (b) a wider range of colors/grayscales are available
if you use a postscript device. See below for details and examples.

Details: 
--------

> Q (1) Is the map() function available in S-plus 4.5?

[Doug Johnson:]
>It is included in S-PLUS 4.5 and S-PLUS 2000.  You need to attach the
>maps library before you can access any of the functions:
>
>        library(maps)
>        map("county")  # draw USA with all the counties.
>
>The on-line help file for 'map()' needs to make this clear to the user,
>but doesn't.  I have posted a bug report against the help file, and
>have linked it to your question in our database.

> > Q(2) Is there a problem getting map() to shade polygons properly 
> > --- something to do with the method for
> > translating data values into color values?

[Greg Snow:] 
> The potential problem is that map() will color the areas, but it uses
> integers that corespond to the graphics device colors.  You need to set
> the colors through the graphics device first, then make the plot (and
> unfortunately I think you only have 16 colors to work with on the screen,
> but you can increase it if you print to a postscript device.  Here is a
> simple example where I use various shades of blue (not evenly spaced so
> the numbers could represent real data scaled to be between 0 and 255)
> 
> > library(maps)
> > temp.col <- c(0,10,20,30,100,150,175,200,210,255)
> > graphsheet(color.table=cbind(temp.col,temp.col,255))
> > map('county','Washington',fill=T,col=1:10)
> > map('county','Washington',add=T)
> 
> That should do it for you, jus replace temp.col with values determined by
> the data (you could wrap this all in a function to make it easier).  You
> can replace the graphsheet line with a call to postscript(color= ... ) to
> get more color levels (though trying to distinguish more may not add
> much).  The second call to map() draws borders in in black, it is not
> necessary, but it makes it look nicer.
> 

[Stephen Kaluzny:]
>You can only fill map polygons with a single color with
>each call to map() but you can use the add=T argument to add additional
>polygons in different colors to the current map.  E.g.
>
>        map("county", region="new jersey")
>        map("county", region=
>               c("new jersey,ocean",
>                "new jersey,cape may"),
>                add=T, fill=T, col=2)  # Cape May and Ocean Co. in col 2
>        map("county", region=
>                c("new jersey,morris",
>                "new jersey,hudson"),
>                add=T, fill=T, col=3)  # Morris and Hudson Co. in col 3
>
>The mapname() function, called by map(), may be useful
>It returns a named vector of the polygons that will be drawn in a call to
>map().  The function has no help file but its usage is straightforward.
>E.g.
>
>        mapname("state", "*")  # all the polygons drawn by map("state")
>        mapname("county", "new jersey")  # all the polygons drawn by
>                                         #   map("county", "new jersey")
>
>Note that some counties in the USA are drawn as more than one polygon.



-- 
Kieran Healy              email: kjhealy@princeton.edu 
Department of Sociology   
Princeton University      
Princeton, NJ 08544-1010  http://www.princeton.edu/~kjhealy
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

home help back first fref pref prev next nref lref last post