smoothScatter          package:geneplotter          R Documentation

_S_c_a_t_t_e_r_p_l_o_t_s _w_i_t_h _s_m_o_o_t_h_e_d _d_e_n_s_i_t_i_e_s _c_o_l_o_r _r_e_p_r_e_s_e_n_t_a_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     'smoothScatter' produces a smoothed color density representation
     of the scatterplot, obtained through a kernel density estimate.
     'densCols' produces a vector containing colors which encode the
     local densities at each point in a scatterplot.

_U_s_a_g_e:

     smoothScatter(x, y=NULL,
                   nbin=128,
                   bandwidth,
                   colramp=colorRampPalette(c("white", brewer.pal(9, "Blues"))),
                   nrpoints=100,
                   transformation=function(x) x^.25,
                   xlab=NULL, ylab=NULL, postPlotHook=box, pch=".", cex=1, ...) 

          densCols(x, y=NULL,
                   nbin=128,
                   bandwidth,
                   colramp=colorRampPalette(brewer.pal(9, "Blues")[-(1:3)]))

_A_r_g_u_m_e_n_t_s:

       x: Numeric vector containing x-values or n by 2 matrix
          containing x and y values.

       y: Numeric vector containing y-values (optional). The length of
          'x' must be the same as that of 'y'.

    nbin: Numeric vector of length 1 (for both directions) or 2 (for x
          and y separately) containing the number of equally spaced
          grid points for the density estimation.

bandwidth: Numeric vector: the smoothing bandwidth. If missing, these
          functions come up with a more or less useful guess. This
          parameter then gets passed on to the function 'bkde2D'.

 colramp: Function accepting an integer 'n' as an argument and
          returning 'n' colors.

nrpoints: Numeric vector of length 1 giving number of points to be
          superimposed on the density image. The first 'nrpoints'
          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 'nrpoints = Inf'.

transformation: Function that maps the density scale to the color
          scale.

    xlab: Character. Gets passed on to 'image'

    ylab: Character. Gets passed on to 'image'

postPlotHook: Either 'NULL' or a function with no arguments that will
          be called after 'image'.

     pch: 'points' parameter setting

     cex: character expansion parameter setting (see 'par') passed to
          the 'points' phase of the function

     ...: Further arguments that are passed on to 'image'.

_D_e_t_a_i_l_s:

     These functions are convenience wrappers around 'bkde2D'.

     The treatment of the 'x' and 'y' arguments attempts to be
     consistent with that e.g. of 'plot.default'.

     See examples for how to use this function together withn 'pairs'.

_V_a_l_u_e:

     'smoothScatter' is called for its side-effect, producing a plot on
     the current graphics device. 'densCols' returns a vector of length
     'nrow(x)' that contains colors to be used in a subsequent
     scatterplot. Each color represents the local density around the
     corresponding point.

_A_u_t_h_o_r(_s):

     Florian Hahne <f.hahne@dkfz.de>

_S_e_e _A_l_s_o:

     'bkde2D'

_E_x_a_m_p_l_e_s:

     if(interactive()) {
       x1  <- matrix(rnorm(1e4), ncol=2)
       x2  <- matrix(rnorm(1e4, mean=3, sd=1.5), ncol=2)
       x   <- rbind(x1,x2)

       oldpar <- par(mfrow=c(2,2))
       smoothScatter(x, nrpoints=0)
       smoothScatter(x)
       smoothScatter(x,nrpoints=Inf,colramp=colorRampPalette(RColorBrewer::brewer.pal(9, "YlOrRd")),bandwidth=1)  

       colors  <- densCols(x)
       plot(x, col=colors, 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(...) {par(new=TRUE);smoothScatter(..., nrpoints=0)})

       par(oldpar)
     }

