[R] Why does smoothScatter clip when xlim and ylim increased?
Duncan Murdoch
murdoch at stats.uwo.ca
Sat Feb 6 14:15:43 CET 2010
On 06/02/2010 7:51 AM, Jennifer Lyon wrote:
> Hi:
>
> Is there a way to get smoothScatter to not clip when I increase the
xlim and
> ylim parameters?
> Consider the following example:
>
> set.seed(17)
> x1<-rnorm(100)
> x2<-rnorm(100)
> smoothScatter(x1,x2)
>
> #Now if I increase xlim and ylim notice that the plot seems to be
clipped at
> the former xlim, and ylim boundaries:
>
> smoothScatter(x1,x2, xlim=c(-5,5), ylim=c(-5,5))
If you follow the links on the help page, you'll see that smoothScatter
uses bkde2D, which has a range.x argument to control the range of the
smoothing. The smoothScatter function never passes the xlim and ylim
values to bkde2D, only to the plotting functions, presumably because the
author expected you to use them to limit the range, not extend it.
You can get the behaviour you want with specified xlim and ylim by
modifying one line in smoothScatter:
map <- grDevices:::.smoothScatterCalcDensity(x, nbin, bandwidth)
should become
map <- grDevices:::.smoothScatterCalcDensity(x, nbin, bandwidth,
list(xlim, ylim))
(You can use fix(smoothScatter) to edit your own local copy of
smoothScatter and make this change.)
However, this messes up the default plot, so a better patch would be
needed to permanently fix this.
Duncan Murdoch
More information about the R-help
mailing list