Summary, was [R] Plotting panels at arbitrary places on a map, rather than on a lattice

Michael Dewey m.dewey at iop.kcl.ac.uk
Wed Oct 6 18:34:28 CEST 2004


At 17:58 01/10/04, Michael Dewey wrote:
>I think it is easiest to describe
>what I want in terms of the concrete
>problem I have.
>
>I have data from a number of countries
>in each of which a sample of people was
>interviewed. In presenting the results
>in a forthcoming collaborative publication
>much emphasis will be placed on the
>multi-centre nature of the study. Although
>I suspect colleagues may do this with
>shaded maps I would prefer to avoid
>them as (a) they present one fact per
>country per map (b) they are unfair to
>the Netherlands and other high density
>countries.
>
>What I would like to do is to make
>the background represent Europe (ideally
>with a map but that is a frill) then
>place simple scattergrams (or radar plots)
>on it located roughly where the country
>is. Another way of describing it might
>be to say that I want something like
>the panels produced by lattice but at
>arbitrary coordinates rather than on
>a rectangular grid. I suspect I have
>to do this from scratch and I would
>welcome hints.
>
>Am I right that there is no off the
>shelf way to do this?
>
>Is grid the way to go? Looking at the
>article in Rnews 2(2) and a brief scan
>of the documentation suggests so.
>If grid is the way to go then bearing
>in mind I have never used grid before
>(a) any hints about the overall
>possible solution structure
>would be welcome (b) is this realistic to
>do within a week or shall I revert to
>lattice and lose the geography?
>
>Is there a simple way to draw a map
>in the background? It needs to cover
>as far as Sweden, Spain and Greece.
>It can be crude,
>as long as Italy looks roughly like
>a boot that is fine. I am an epidemiologist
>not a geographer.
>

I received some very helpful hints and was able to get a satisfactory solution.
Roger Bivand  pointed me in the right way with map. After loading maps
and mapproj I go

map("world", region = c("France", "Belgium", "Greece", "Spain", "Italy",
    "Switzerland", "Sweden", "Germany", "Netherlands", "Austria",
    "Denmark", "Sicily", "Sardinia"),
    xlim = c(-10, 30), ylim = c(30, 60),
    projection = "albers", parameters = c(30,60), col = "lightgreen")

then bearing in mind that my data is in a file called merg
which contains the coordinates and the data to plot

merg$x <- mapproject(merg$long,merg$lat)$x
merg$y <- mapproject(merg$long,merg$lat)$y

gets the coordinates in the new system.
Deepayan Sarkar reminded me about stars which I should
have remembered myself from reading MASS.
I now go

stars(2*merg[,ord+4], scale = FALSE, len = 0.07,
    locations = cbind(merg$x,merg$y), labels = NULL,
    cex = 0.3,
    key.loc = c(mapproject(-10,60)$x,mapproject(-10,60)$y),
    add = TRUE
)

and get a plot which does what I wanted.

Roger had pointed out that gridbase was probably the way to put 
scatterplots on the map
but I decided after looking at the stars that scatterplots would end up too 
small to use
so I stayed with lattice for them.
(When I said scattergrams I meant what nearly everyone else calls 
scatterplots.)

Thanks to both of them, and to the people who made maps and stars so easy
when you know what to look for.



Michael Dewey
m.dewey at iop.kcl.ac.uk




More information about the R-help mailing list