[R] overlaying a levelplot on a map plot

Felix Andrews felix at nfrac.org
Fri Apr 23 03:08:44 CEST 2010


You are plotting the entire lattice plot (including axes, margins etc)
in the grid viewport. What you want to do is to call the panel
function, panel.levelplot(), instead.

However, why not just

mm <- map('worldHires', plot = FALSE)
levelplot(z~x+y,xyz, mm = mm, panel = function(..., mm) {
    panel.levelplot(...)
    panel.lines(mm$x, mm$y)
})


On 23 April 2010 06:16, Simon Goodman <s.j.goodman at leeds.ac.uk> wrote:
> Thanks for those pointers.... making some progress now
>
> The following will put the levelplot on to the map, but the not with the
> co-ordinates aligned...
> The level plot appears on a slightly larger scale compared to the underlying
> map.
>
> In both the map and levelplot, the coordinates are in lon, lat decimal
> degrees.
> Hopefully I'm nearly there, with 1 or 2 tweaks.
>
>
> library(gridBase)
> mlat<-c(n1,n2)
> mlon<-c(n3,n4)
> map('worldHires', xlim = range(mlon), ylim = range(mlat))
> axis(1);axis(2);axis(3);axis(4)
>
> lvl.plot<-levelplot(z~x+y,xyz,pretty=TRUE,at=at,col.regions=cl)
> vps <- baseViewports()
> pushViewport(vps$inner, vps$figure, vps$plot)
> pushViewport(viewport(print(lvl.plot, newpage=FALSE)))
> popViewport()
> popViewport(3)
>
> However after the line 'pushViewport(viewport(print(lvl.plot,
> newpage=FALSE)))' an error is returned:
>
> Error in unit(x, default.units) :
>  (list) object cannot be coerced to type 'double'
>
>
>
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/overlaying-a-levelplot-on-a-map-plot-tp2019419p2021128.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andrews at anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/



More information about the R-help mailing list