R: Rootograms

rootogram {vcd} | R Documentation

## Rootograms

### Description

Rootograms of observed and fitted values.

### Usage

    ## Default S3 method:
    rootogram(x, fitted, names = NULL, scale = c("sqrt", "raw"),
      type = c("hanging", "standing", "deviation"),
      shade = FALSE, legend = TRUE,
      legend_args = list(x = 0, y = 0.2, height = 0.6), df = NULL,
      rect_gp = NULL, rect_gp_args = list(),
      lines_gp = gpar(col = "red", lwd = 2),
      points_gp = gpar(col = "red"), pch = 19,
      xlab = NULL, ylab = NULL, ylim = NULL,
      main = NULL, sub = NULL,
      margins = unit(0, "lines"),
      title_margins = NULL, legend_width = NULL,
      main_gp = gpar(fontsize = 20),
      sub_gp = gpar(fontsize = 15),
      name = "rootogram", prefix = "",
      keep_aspect_ratio = FALSE,
      newpage = TRUE, pop = TRUE,
      return_grob = FALSE, ...)

### Arguments

`x` | either a vector or a 1-way table of frequencies.
`fitted` | a vector of fitted frequencies.
`names` | a vector of names passed to `grid_barplot`, if set to `NULL` the names of `x` are used.
`scale` | a character string indicating whether the values should be plotted on the raw or square root scale.
`type` | a character string indicating if the bars for the observed frequencies should be `hanging` or `standing` or indicate the `deviation` between observed and fitted frequencies.
`shade` | logical specifying whether `rect_gp` should be set to colors corresponding to the pearson residuals, i.e., if a residual-based shading should be applied to the bars.
`legend` | either a legend-generating function, or a legend function (see details and `legends`), or a logical. If `legend` is `NULL` or `TRUE` and `gp` is a function, legend defaults to `legend_resbased`.
`legend_args` | list of arguments for the legend-generating function, if specified.
`df` | degrees of freedom passed to the shading functions used for inference.
`rect_gp` | a `"gpar"` object controlling the grid graphical parameters of the rectangles, shading function or a corresponding generating function (see `shadings`). If unspecified and no shading is applied, defaults to light grey fill color for the bars.
`rect_gp_args` | list of arguments for the shading-generating function, if specified for `rect_gp`.
`lines_gp` | a `"gpar"` object controlling the grid graphical parameters of the lines.
`points_gp` | a `"gpar"` object controlling the grid graphical parameters of the points.
`pch` | plotting character for the points.
`xlab` | a label for the x axis.
`ylab` | a label for the y axis.
`ylim` | limits for the y axis.
`main` | either a logical, or a character string used for plotting the main title. If `main` is a logical and `TRUE`, the name of the object supplied as `x` is used.
`sub` | a character string used for plotting the subtitle. If `sub` is a logical and `TRUE` and `main` is unspecified, the name of the object supplied as `x` is used.
`margins` | either an object of class `"unit"` of length 4, or a numeric vector of length 4. The elements are recycled as needed. The four components specify the top, right, bottom, and left margin of the plot, respectively. When a numeric vector is supplied, the numbers are interpreted as `"lines"` units. In addition, the unit or numeric vector may have named arguments (top, right, bottom, and left), in which case the non-named arguments specify the default values (recycled as needed), overloaded by the named arguments.
`title_margins` | either an object of class `"unit"` of length 2, or a numeric vector of length 2. The elements are recycled as needed. The two components specify the top and bottom title margin of the plot, respectively. The default for each specified title are 2 lines (and 0 else), except when a legend is plotted and `keep_aspect_ratio` is `TRUE`: in this case, the default values of both margins are set as to align the heights of legend and actual plot. When a numeric vector is supplied, the numbers are interpreted as `"lines"` units. In addition, the unit or numeric vector may have named arguments (top and bottom), in which case the non-named argument specify the default value (recycled as needed), overloaded by the named arguments.
`legend_width` | An object of class `"unit"` of length 1 specifying the width of the legend (if any). Default: 5 lines.
`main_gp, sub_gp` | object of class `"gpar"` containing the graphical parameters used for the main (sub) title, if specified.
`name` | name of the plotting viewport.
`keep_aspect_ratio` | logical indicating whether the aspect ratio should be fixed or not.
`prefix` | optional character string used as a prefix for the generated viewport and grob names.
`newpage` | logical. Should `grid.newpage` be called before plotting?
`pop` | logical. Should the viewport created be popped?
`return_grob` | logical. Should a snapshot of the display be returned as a grid grob?
`...` | further arguments passed to `grid_barplot`.

### Details

The observed frequencies are displayed as bars and the fitted frequencies as a line. By default a sqrt scale is used to make the smaller frequencies more visible.

### Author(s)

Achim Zeileis Achim.Zeileis@R-project.org, David Meyer David.Meyer@R-project.org

### References

J. W. Tukey (1977), Exploratory Data Analysis. Addison Wesley, Reading, MA.

M. Friendly (2000), Visualizing Categorical Data. SAS Institute, Cary, NC.

### See Also

`grid_barplot`

### Examples

    ## Simulated data examples:
    dummy <- rnbinom(200, size = 1.5, prob = 0.8)
    observed <- table(dummy)
    fitted1 <- dnbinom(as.numeric(names(observed)),
                       size = 1.5, prob = 0.8) * sum(observed)
    fitted2 <- dnbinom(as.numeric(names(observed)),
                       size = 2, prob = 0.6) * sum(observed)
    rootogram(observed, fitted1)
    rootogram(observed, fitted2)

    ## Real data examples:
    data("HorseKicks")
    HK.fit <- goodfit(HorseKicks)
    summary(HK.fit)
    plot(HK.fit)
    ## or equivalently
    rootogram(HK.fit)

    data("Federalist")
    F.fit <- goodfit(Federalist, type = "nbinomial")
    summary(F.fit)
    plot(F.fit)

    ## (Pearson) residual-based shading
    data("Federalist")
    Fed_fit0 <- goodfit(Federalist, type = "poisson")
    plot(Fed_fit0, shade = TRUE)

[Package vcd version 1.4-4 Index]