Jennifer Lyon
2010-Feb-06 12:51 UTC
[R] Why does smoothScatter clip when xlim and ylim increased?
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)) Thanks. Jen sessionInfo() R version 2.10.1 (2009-12-14) i686-pc-linux-gnu locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics utils datasets grDevices methods base other attached packages: [1] RColorBrewer_1.0-2 loaded via a namespace (and not attached): [1] KernSmooth_2.23-3 [[alternative HTML version deleted]]
Duncan Murdoch
2010-Feb-06 13:15 UTC
[R] Why does smoothScatter clip when xlim and ylim increased?
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