Skip to content

svyplot and svysmooth with hexbin

5 messages · Anthony Damico, Durant, James T. (ATSDR/DTEM/PRMSB), Paul Murrell +1 more

#
Hi
On 19/10/2012 6:49 a.m., Durant, James T. (ATSDR/DCHI/SSB) wrote:
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

  
    
#
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: