A huge plot (scatter plot matrix)

One disadvantage of recordPlot() is that it may not be able to record huge plots due to memory limits, e.g. a scatter plot matrix of tens of thousands of points:

# generate some random data
dat = matrix(runif(100000), ncol=5)
dat[, 3] = -.2 * dat[, 1] + .8 * dat[, 2] # to make the plot less boring
```r
pairs(dat)

But scatter plots with such a large number of points are usually difficult to read (basically you can see nothing), so we'd better use some alternative ways to visualize them. For example, we can use 2D density estimates and draw contour plots, or just plot the LOWESS curve.

dens2d = function(x, y, ...) {
  library(MASS)
  res = kde2d(x, y)
  with(res, contour(x, y, z, add = TRUE))
}
pairs(dat, lower.panel = dens2d, upper.panel = function(x, y, ...) {
  lines(lowess(y ~ x), col = 'red')
})


Try the parsermd package in your browser

Any scripts or data that you put into this service are public.

parsermd documentation built on May 20, 2021, 5:08 p.m.