histogram              package:lattice              R Documentation

_H_i_s_t_o_g_r_a_m_s _a_n_d _K_e_r_n_e_l _D_e_n_s_i_t_y _P_l_o_t_s

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

     Draw Histograms and Kernel Density Plots

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

     histogram(formula,
               data, 
               type = c("percent", "count", "density"),
               nint = if(is.factor(x)) length(levels(x))
                      else round(log2(length(x))+1),
               endpoints = range(x[!na.x]),
               breaks = if(is.factor(x)) seq(0.5, length = length(levels(x))
               + 1) else do.breaks(endpoints, nint),
               equal.widths = FALSE, 
               ...)

     densityplot(formula, data, n = 50, plot.points = TRUE, ref = FALSE,
                 ...)

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

 formula: A formula of the form `~ x | g1 * g2 * ...' indicates that
          histograms of `x' should be produced conditioned on the
          levels of the (optional) variables `g1,g2,...'. When the
          conditioning variables `g1,g2,...' are missing, the leading
          `~' can be dropped.

          `x' can be numeric (or factor for `histogram'), and each of
          `g1,g2,...' must be either factors or shingles. 

    data: optional data frame in which variables are to be evaluated

    type: Character string indicating type of histogram to be drawn.
          ``percent'' and ``count'' give relative frequency and
          frequency histograms, and can be misleading when breakpoints
          are not equally spaced. ``density'' produces a density scale
          histogram. (See second example below.) (This option is
          missing in Splus.)

          `type' defaults to ``percent'', except when the breakpoints
          are unequally spaced or `breaks = NULL'. 

    nint: Number of bins. Applies only when `breaks' is unspecified in
          the call. 

endpoints: vector of length 2 indicating the range of x-values that is
          to be covered by the  histogram. Again, applies only when
          `breaks' is unspecified. 

  breaks: numeric vector of length = (number of bins + 1) defining the
          breakpoints of the bins. Note that when breakpoints are not
          equally spaced, the only value of `type' that makes sense is
          density.

          Usually all panels use the same breakpoints. This can be
          changed by specifying `breaks = NULL'. This has the effect of
          letting each panel choose its own breakpoints. The choice of
          these breakpoints are made as follows: The number of bins is
          calculated by the formula for `nint' above, and then
          breakpoints are chosen according to the value of
          `equal.widths'. 

equal.widths: logical, relevant only when `breaks=NULL'. If `TRUE',
          equally spaced bins will be selected, otherwise, 
          approximately equal area bins will be selected (this would
          mean that the breakpoints will not be equally spaced). 

       n: number of points at which density is to be evaluated

plot.points: logical specifying whether the `x' values should be
          plotted. 

     ref: logical specifying whether a reference x-axis should be
          drawn.

     ...: other arguments. In the case of `densityplot', if the default
          panel function is used, then arguments appropriate to
          `density' can be included. This can control the details of
          how the Kernel Density Estimates are calculated. See
          documentation for `density' for details. 

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

     `histogram' draws Conditional Histograms, while `densityplot'
     draws Conditional Kernel Density Plots.  The density estimate in
     `densityplot' is actually calculated using the function `density',
     and all arguments accepted by it can be passed (as `...') in the
     call to `densityplot' to control the output. See documentation of
     `density' for details. (Note: The default value of the argument
     `n' of `density' is changed to 50.)

     These and all other high level Trellis functions have several
     arguments in common. These are extensively documented only in the
     help page for `xyplot', which should be consulted to learn more
     detailed usage.

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

     An object of class ``trellis'', plotted by default by
     `print.trellis'.

_N_o_t_e:

     The form of the arguments accepted by the default panel function
     `panel.histogram' is different from that in S-Plus. Whereas S-Plus
     calculates the heights inside `histogram' and passes only the
     breakpoints and the heights to the panel function, here the
     original variable `x' is passed along with the breakpoints. This
     allows plots as in the second example below.

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

     Deepayan Sarkar deepayan@stat.wisc.edu

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

     `xyplot', `panel.histogram', `density', `panel.densityplot',
     `panel.mathdensity', `Lattice'

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

     data(singer)
     histogram( ~ height | voice.part, data = singer, nint = 17,
               endpoints = c(59.5, 76.5), layout = c(2,4), aspect = 1,
               xlab = "Height (inches)")
     ## The following would not be possible in S-Plus
     histogram( ~ height | voice.part, data = singer,
               xlab = "Height (inches)", type = "density",
               panel = function(x, ...) {
                   panel.histogram(x, ...)
                   panel.mathdensity(dmath = dnorm,
                                     args = list(mean=mean(x),sd=sd(x)))
               } )
     densityplot( ~ height | voice.part, data = singer, layout = c(2, 4),  
                 xlab = "Height (inches)", bw = 5)

