EVOLUTION-MANAGER
Edit File: smoothScatter.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Scatterplots with Smoothed Densities Color Representation</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for smoothScatter {graphics}"><tr><td>smoothScatter {graphics}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Scatterplots with Smoothed Densities Color Representation</h2> <h3>Description</h3> <p><code>smoothScatter</code> produces a smoothed color density representation of a scatterplot, obtained through a (2D) kernel density estimate. </p> <h3>Usage</h3> <pre> smoothScatter(x, y = NULL, nbin = 128, bandwidth, colramp = colorRampPalette(c("white", blues9)), nrpoints = 100, ret.selection = FALSE, pch = ".", cex = 1, col = "black", transformation = function(x) x^.25, postPlotHook = box, xlab = NULL, ylab = NULL, xlim, ylim, xaxs = par("xaxs"), yaxs = par("yaxs"), ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x, y</code></td> <td> <p>the <code>x</code> and <code>y</code> arguments provide the x and y coordinates for the plot. Any reasonable way of defining the coordinates is acceptable. See the function <code><a href="../../grDevices/html/xy.coords.html">xy.coords</a></code> for details. If supplied separately, they must be of the same length.</p> </td></tr> <tr valign="top"><td><code>nbin</code></td> <td> <p>numeric vector of length one (for both directions) or two (for x and y separately) specifying the number of equally spaced grid points for the density estimation; directly used as <code>gridsize</code> in <code><a href="../../KernSmooth/html/bkde2D.html">bkde2D</a>()</code>.</p> </td></tr> <tr valign="top"><td><code>bandwidth</code></td> <td> <p>numeric vector (length 1 or 2) of smoothing bandwidth(s). If missing, a more or less useful default is used. <code>bandwidth</code> is subsequently passed to function <code><a href="../../KernSmooth/html/bkde2D.html">bkde2D</a></code>.</p> </td></tr> <tr valign="top"><td><code>colramp</code></td> <td> <p>function accepting an integer <code>n</code> as an argument and returning <code>n</code> colors.</p> </td></tr> <tr valign="top"><td><code>nrpoints</code></td> <td> <p>number of points to be superimposed on the density image. The first <code>nrpoints</code> points from those areas of lowest regional densities will be plotted. Adding points to the plot allows for the identification of outliers. If all points are to be plotted, choose <code>nrpoints = Inf</code>.</p> </td></tr> <tr valign="top"><td><code>ret.selection</code></td> <td> <p><code><a href="../../base/html/logical.html">logical</a></code> indicating to return the ordered indices of “low density” points if <code>nrpoints > 0</code>.</p> </td></tr> <tr valign="top"><td><code>pch, cex, col</code></td> <td> <p>arguments passed to <code><a href="points.html">points</a></code>, when <code>nrpoints > 0</code>: point symbol, character expansion factor and color, see also <code><a href="par.html">par</a></code>.</p> </td></tr> <tr valign="top"><td><code>transformation</code></td> <td> <p>function mapping the density scale to the color scale.</p> </td></tr> <tr valign="top"><td><code>postPlotHook</code></td> <td> <p>either <code>NULL</code> or a function which will be called (with no arguments) after <code><a href="image.html">image</a></code>.</p> </td></tr> <tr valign="top"><td><code>xlab, ylab</code></td> <td> <p>character strings to be used as axis labels, passed to <code><a href="image.html">image</a></code>.</p> </td></tr> <tr valign="top"><td><code>xlim, ylim</code></td> <td> <p>numeric vectors of length 2 specifying axis limits.</p> </td></tr> <tr valign="top"><td><code>xaxs, yaxs, ...</code></td> <td> <p>further arguments passed to <code><a href="image.html">image</a></code>, e.g., <code>add=TRUE</code> or <code>useRaster=TRUE</code>.</p> </td></tr> </table> <h3>Details</h3> <p><code>smoothScatter</code> produces a smoothed version of a scatter plot. Two dimensional (kernel density) smoothing is performed by <code><a href="../../KernSmooth/html/bkde2D.html">bkde2D</a></code> from package <a href="https://CRAN.R-project.org/package=KernSmooth"><span class="pkg">KernSmooth</span></a>. See the examples for how to use this function together with <code><a href="pairs.html">pairs</a></code>. </p> <h3>Value</h3> <p>If <code>ret.selection</code> is true, a vector of integers of length <code>nrpoints</code> (or smaller, if there are less finite points inside <code>xlim</code> and <code>ylim</code>) with the indices of the low-density points drawn, ordered with lowest density first. </p> <h3>Author(s)</h3> <p>Florian Hahne at FHCRC, originally</p> <h3>See Also</h3> <p><code><a href="../../KernSmooth/html/bkde2D.html">bkde2D</a></code> from package <a href="https://CRAN.R-project.org/package=KernSmooth"><span class="pkg">KernSmooth</span></a>; <code><a href="../../grDevices/html/densCols.html">densCols</a></code> which uses the same smoothing computations and <code><a href="../../grDevices/html/densCols.html">blues9</a></code> in package <span class="pkg">grDevices</span>. </p> <p><code><a href="../../stats/html/scatter.smooth.html">scatter.smooth</a></code> adds a <code><a href="../../stats/html/loess.html">loess</a></code> regression smoother to a scatter plot. </p> <h3>Examples</h3> <pre> ## A largish data set n <- 10000 x1 <- matrix(rnorm(n), ncol = 2) x2 <- matrix(rnorm(n, mean = 3, sd = 1.5), ncol = 2) x <- rbind(x1, x2) oldpar <- par(mfrow = c(2, 2), mar=.1+c(3,3,1,1), mgp = c(1.5, 0.5, 0)) smoothScatter(x, nrpoints = 0) smoothScatter(x) ## a different color scheme: Lab.palette <- colorRampPalette(c("blue", "orange", "red"), space = "Lab") i.s <- smoothScatter(x, colramp = Lab.palette, ## pch=NA: do not draw them nrpoints = 250, ret.selection=TRUE) ## label the 20 very lowest-density points,the "outliers" (with obs.number): i.20 <- i.s[1:20] text(x[i.20,], labels = i.20, cex= 0.75) ## somewhat similar, using identical smoothing computations, ## but considerably *less* efficient for really large data: plot(x, col = densCols(x), pch = 20) ## use with pairs: par(mfrow = c(1, 1)) y <- matrix(rnorm(40000), ncol = 4) + 3*rnorm(10000) y[, c(2,4)] <- -y[, c(2,4)] pairs(y, panel = function(...) smoothScatter(..., nrpoints = 0, add = TRUE), gap = 0.2) par(oldpar) </pre> <hr /><div style="text-align: center;">[Package <em>graphics</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>