hist2d                package:gplots                R Documentation

_C_o_m_p_u_t_e _a_n_d _P_l_o_t _a _2-_D_i_m_e_n_s_i_o_n_a_l _H_i_s_t_o_g_r_a_m

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

     Compute and plot a 2-dimensional histogram.

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

     hist2d(x,y=NULL, nbins=200, same.scale=FALSE, na.rm=TRUE, show=TRUE,
            col=c("black", heat.colors(12)), ... )

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

       x: either a vector containing the x coordinates or a matrix with
          2 columns. 

       y: a vector contianing the y coordinates, not required if `x' is
          matrix

   nbins: number of bins in each dimension. May be a scalar or a 2
          element vector.  Defaults to 200.

same.scale: use a single range for x and y. Defaults to FALSE.

   na.rm: Indicates whether missing values should be removed. Defaults
          to TRUE.

    show: Indicates whether the histogram be displayed using 'image'
          once it has been computed. Defaults to TRUE.

     col: Colors for the histogram. Defaults to "black" for bins
          containing no elements, a set of 16 heat colors for other
          bins.

     ...: Parameters passed to the image function. 

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

     This fucntion creates a 2-dimensional histogram by cutting the x
     and y dimensions into 'nbins' sections.  A 2-dimensional matrix is
     then constucted which holds the counts of the number of observed
     (x,y) pairs that fall into each bin.  If 'show=TRUE', this matrix
     is then then passed to 'image' for display.

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

     A list containing 3 elements: 

  counts: Matrix containing the number of points falling into each bin

       x: lower x limit of each bin

       y: lower y limit of each bin

_A_u_t_h_o_r(_s):

     Gregory R. Warnes gregory.r.warnes@pfizer.com

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

     'image', 'persp', 'hist'

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

        # example data, bivariate normal, no correlation
        x <- rnorm(2000, sd=4)
        y <- rnorm(2000, sd=1)

        # separate scales for each axis, this looks circular
        hist2d(x,y)

        # same scale for each axis, this looks oval
        hist2d(x,y, same.scale=TRUE)

        # use different # bins in each dimension
        hist2d(x,y, same.scale=TRUE, nbins=c(100,200) )

        # use the hist2d function to create inputs for a perspective plot ...
        h2d <- hist2d(x,y,show=FALSE, same.scale=TRUE, nbins=c(20,30))
        persp( h2d$x, h2d$y, h2d$counts,
               ticktype="detailed", theta=30, phi=30,
               expand=0.5, shade=0.5, col="cyan", ltheta=-30)

        # for contour (line) plot ...
        contour( h2d$x, h2d$y, h2d$counts, nlevels=4 )

        # for a filled contour plot ...
        filled.contour( h2d$x, h2d$y, h2d$counts, nlevels=4,
                        col=gray((4:0)/4) )

