[R] svyplot and svysmooth with hexbin
Paul Murrell
p.murrell at auckland.ac.nz
Thu Oct 18 21:39:04 CEST 2012
Hi
On 19/10/2012 6:49 a.m., Durant, James T. (ATSDR/DCHI/SSB) wrote:
> Hi all-
>
> So sorry to bother you all with something pretty basic.
>
> I am trying to add the lines method output from svysmooth to a
> svyplot with style="grayhex". However, the line either appears in
> the wrong place or if I am running in R Studio it causes the system
> to crash.
>
> I know this is something to do with Lattice graphics, but for the
> life of me I can not figure out how. Dr. Lumley in his excellent book
> on page 118 mentions that there is code on his website to do this,
> but I can not find it.
There may be a higher-level interface to do this, but here's a
nuts-and-bolts solution to do what I think you want ...
# Save the result from svyplot() call.
temp <- svyplot(api00~api99, dclus2, style="grayhex")
# Part of the result is the viewport that svyplot()
# used to draw the plot (technically its a hexViewport).
# Push that hexViewport so we can draw in the original
# plot region and scales.
pushHexport(temp$plot.vp)
# Use grid.lines() to draw the smoother relative to the
# "native" scales in the plot hexViewport.
lapply(s1, function(z) { grid.lines(z$x, z$y, default="native") })
Hope that helps
Paul
>
>
> So for example:
>
> library(survey)
>
> data(api) dclus2<-svydesign(id=~dnum+snum, fpc=~fpc1+fpc2,
> data=apiclus2) svyplot(api00~api99, dclus2)
>
> s1<-svysmooth(api00~api99, dclus2)
>
> lines(s1)
>
> #works
>
> svyplot(api00~api99, dclus2, style="grayhex") lines(s1)
>
> #does not work (line either appears in the wrong position in RGui or
> crashes RStudio).
>
>
> VR
>
> James
>
> James T. Durant, MSPH CIH Environmental Health Scientist US Agency
> for Toxic Substances and Disease Registry Atlanta, GA 30341
> 770-488-0668
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________ 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.
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/
More information about the R-help
mailing list