interaction {lattice}R Documentation

Functions to Interact with Lattice Plots

Description

The classic Trellis paradigm is to plot the whole object at once, without the possibility of interacting with it afterwards. However, by keeping track of the grid viewports where the panels and strips are drawn, it is possible to go back to them afterwards and enhance them one panel at a time. These functions provide convenient interfaces to help in this. Note that these are still experimental and the exact wn breakrated by a + sign. What happens in this case is described in details in the documentation for xyplot. Note that in either form, all the variables involved in the formula have to have same length.
For the numeric and factor methods, x replaces the x vector described above. Conditioning is not allowed in these cases.
data For the formula method, an optional data frame in which variables are to be evaluated. Ignored with a warning in other cases. 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.
type defaults to "percent", except when the breakpoints are unequally spaced or breaks = NULL, when it defaults to "density".
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. In do.breaks, this specifies the interval that is to be divided up. 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 panel The function that uses the packet (subset of display variables) corresponding to a panel to create a display. Default panel functions are documented separately, and often have arguments that can be used to customize its display in various ways. Such arguments can usually be directly supplied to the high level function. allow.multiple, outer, auto.key, aspect, prepanel, scales, strip, groups, xlab, xlim, ylab, ylim, drop.unused.levels, default.scales, subscripts, subset See xyplot bw, adjust, kernel, window, width, give.Rkern, from, to, cut, na.rm arguments to density, passed on as appropriate ... Further arguments. See corresponding entry in xyplot for non-trivial details.

Details

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.

do.breaks is an utility function that calculates breakpoints given an interval and the number of pieces to break it into.

Value

An object of class "trellis". The update method can be used to update components of the object and the print method (usually called by default) will plot it on an appropriate plotting device.

Note

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.

Author(s)

Deepayan Sarkar Deepayan.Sarkar@R-project.org

See Also

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

Examples

require(stats)
histogram( ~ height | voice.part, data = singer, nint = 17,
          endpoints = c(59.5, 76.5), layout = c(2,4), aspect = 1,
          xlab = "Height (inches)")

histogram( ~ height | voice.part, data = singer,
          xlab = "Height (inches)", type = "density",
          panel = function(x, ...) {
              panel.histogram(x, ...)
              panel.mathdensity(dmath = dnorm, col = "black",
                                args = list(mean=mean(x),sd=sd(x)))
          } )

densityplot( ~ height | voice.part, data = singer, layout = c(2, 4),  
            xlab = "Height (inches)", bw = 5)

[Package lattice version 0.14-13 Index]
./usr/lib/R/library/lattice/html/interaction.html0000644000000000000000000003522110526660740020744 0ustar rootroot R: Functions to Interact with Lattice Plots
interaction {lattice}R Documentation

Functions to Interact with Lattice Plots

Description

The classic Trellis paradigm is to plot the whole object at once, without the possibility of interacting with it afterwards. However, by keeping track of the grid viewports where the panels and strips are drawn, it is possible to go back to them afterwards and enhance them one panel at a time. These functions provide convenient interfaces to help in this. Note that these are still experimental and the exact wn breakrated by a + sign. What happens in this case is described in details in the documentation for xyplot. Note that in either form, all the variables involved in the formula have to have same length.
For the numeric and factor methods, x replaces the x vector described above. Conditioning is not allowed in these cases.
data For the formula method, an optional data frame in which variables are to be evaluated. Ignored with a warning in other cases. 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.
type defaults to "percent", except when the breakpoints are unequally spaced or breaks = NULL, when it defaults to "density".
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. In do.breaks, this specifies the interval that is to be divided up. 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 panel The function that uses the packet (subset of display variables) corresponding to a panel to create a display. Default panel functions are documented separately, and often have arguments that can be used to customize its display in various ways. Such arguments can usually be directly supplied to the high level function. allow.multiple, outer, auto.key, aspect, prepanel, scales, strip, groups, xlab, xlim, ylab, ylim, drop.unused.levels, default.scales, subscripts, subset See xyplot bw, adjust, kernel, window, width, give.Rkern, from, to, cut, na.rm arguments to density, passed on as appropriate ... Further arguments. See corresponding entry in xyplot for non-trivial details.

Details

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.

do.breaks is an utility function that calculates breakpoints given an interval and the number of pieces to break it into.

Value

An object of class "trellis". The update method can be used to update components of the object and the print method (usually called by default) will plot it on an appropriate plotting device.

Note

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.

Author(s)

Deepayan Sarkar Deepayan.Sarkar@R-project.org

See Also

xyplot, panel.histogram, density, panel.densityplot, panel