[R] svyplot and svysmooth with hexbin
Thomas Lumley
tlumley at uw.edu
Thu Oct 18 22:01:41 CEST 2012
Here's an example. The problem is that hexbin uses grid graphics, not
the base graphics that plot.svysmooth() uses, so you need to do the
plotting yourself with grid. The necessary viewport is returned by
svyplot()
hexstuff<-svyplot(api00~api99, design=dstrat, style="hex", xlab="1999
API",ylab="2000 API")
smoothh<-svysmooth(api00~api99, design=dstrat, method="quantreg",quantile=0.75)
smoothl<-svysmooth(api00~api99, design=dstrat, method="quantreg",quantile=0.25)
pushHexport(hexstuff$plot.vp)
grid.lines(smoothh$api99$x,smoothh$api99$y,default.units="native",gp=gpar(col="purple",lwd=2))
grid.lines(smoothl$api99$x,smoothl$api99$y,default.units="native",gp=gpar(col="purple",lwd=2))
popViewport()
-thomas
On Fri, Oct 19, 2012 at 6:49 AM, Durant, James T. (ATSDR/DCHI/SSB)
<hzd3 at cdc.gov> 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.
>
>
>
> 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.
--
Thomas Lumley
Professor of Biostatistics
University of Auckland
More information about the R-help
mailing list