densCols              package:grDevices              R Documentation

_C_o_l_o_r_s _f_o_r _S_m_o_o_t_h _D_e_n_s_i_t_y _P_l_o_t_s

_D_e_s_c_r_i_p_t_i_o_n:

     'densCols' produces a vector containing colors which encode the
     local densities at each point in a scatterplot.

_U_s_a_g_e:

     densCols(x, y = NULL, nbin = 128, bandwidth,
              colramp = colorRampPalette(blues9[-(1:3)]))
     blues9

_A_r_g_u_m_e_n_t_s:

    x, y: the 'x' and 'y' arguments provide the x and y coordinates of
          the points.  Any reasonable way of defining the coordinates
          is acceptable.  See the function 'xy.coords' for details.  If
          supplied separately, they must be of the same length.

    nbin: 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 'gridsize' in 'bkde2D()'.

bandwidth: numeric vector (length 1 or 2) of smoothing bandwidth(s). If
          missing, a more or less useful default is used. 'bandwidth'
          is subsequently passed to function 'bkde2D'.

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

_D_e_t_a_i_l_s:

     'densCols' computes and returns the set of colors that will be
     used in plotting.

     'blues9' is a set of 9 color shades of blue used as the default in
     plotting.

_V_a_l_u_e:

     '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 at FHCRC, originally

_S_e_e _A_l_s_o:

     'bkde2D' from package 'KernSmooth', and 'smoothScatter()' which
     builds on the same computations as 'densCols'.

_E_x_a_m_p_l_e_s:

     x1  <- matrix(rnorm(1e3), ncol=2)
     x2  <- matrix(rnorm(1e3, mean=3, sd=1.5), ncol=2)
     x   <- rbind(x1,x2)

     dcols <- densCols(x)
     graphics::plot(x, col = dcols, pch=20, main = "n = 1000")

