Michael Dewey
2004-Oct-01 16:58 UTC
[R] Plotting panels at arbitrary places on a map, rather than on a lattice
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. Michael Dewey m.dewey at iop.kcl.ac.uk
Deepayan Sarkar
2004-Oct-01 17:45 UTC
[R] Plotting panels at arbitrary places on a map, rather than on a lattice
On Friday 01 October 2004 11:58, 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?I'm not terribly familiar with radar plots (and not at all with scattergrams - what are they?), but if you want radar plots as produced by 'stars', then it seems to have an argument called 'location' which you can use to specify the locations of the stars. That sounds like what you might want. You can also specify 'add = TRUE', which, if you call 'stars' after you have already drawn the map, should superpose your radar plots on the map. I'm not sure how best to draw the map you want, but I'm sure there's a way (maybe using the maps package). Deepayan
Roger Bivand
2004-Oct-01 17:59 UTC
[R] Plotting panels at arbitrary places on a map, rather than on a lattice
On Fri, 1 Oct 2004, 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? >Perhaps rather R-News 3/2, October 2003, "Integrating grid Graphics Output with Base Graphics Output" by Paul Murrell. You might even consider just scanning a basemap, using the pixmap package to read it and display it as a backdrop, and using locator() to get the positions for the localised graphics. For a vector backdrop alternative, try the maps package, world map, and either set plotting limits or choose countries (or both to avoid the French overseas administrative divisions), then locator or the World Factbook to give you a label point.> 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. > > > > > > Michael Dewey > m.dewey at iop.kcl.ac.uk > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! R-project.org/posting-guide.html >-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Breiviksveien 40, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93 e-mail: Roger.Bivand at nhh.no
Michael Dewey
2004-Oct-06 16:34 UTC
Summary, was [R] Plotting panels at arbitrary places on a map, rather than on a lattice
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
Reasonably Related Threads
- Tetrachoric and polychoric ceofficients (for sem) - any tips?
- Creating a "simple" Radar/Spider Plot from Statgraphics
- units for mapproject() function result
- Help on drawing stars and radars in R (update)
- Lattice, skip= and layout= problem, plotting object from nlme output