gginnards (version 0.0.2)

str: Show the structure of a ggplot object.

Description

A str() method tailored to objects of class "ggplot". It adds to the output the size of the object, and the ability to subset individual components.

Usage

# S3 method for ggplot
str(object, ..., max.level = 1, components = TRUE,
  vec.len = 2, list.len = 99, give.attr = FALSE, comp.str = "$ ",
  nest.lev = 0, indent.str = paste(rep.int(" ", max(0, nest.lev + 1)),
  collapse = ".."), size = TRUE)

Arguments

object

ggplot Plot object with embedded data.

...

accept additional parameter arguments

max.level

integer Maximum depth of recursion (of lists within lists ...) to be printed.

components

Vector of components to print, as indexes into object.

vec.len

integer Approximate maximum length allowed when showing the first few values of a vector.

list.len

integer Maximum number of components to show of any list that will be described.

give.attr

logical Flag, determining whether a description of attributes will be shown.

comp.str

character String to be used for separating list components.

nest.lev

numeric current nesting level in the recursive calls to str().

indent.str

character String used for each level of indentation.

size

logical Flag, should the size of the object in bytes be printed?

Value

A NULL is returned invisibly. While a description of the structure of p or its components will be printed in outline form as a "side-effect", with indentation for each level of recursion, showing the internal storage mode, class(es) if any, attributes, and first few elements of each data vector. By default each level of list recursion is indicated and attributes enclosed in angle brackets.

See Also

A summary() method for class ggplot is defined by package 'ggplot2'. Method summary() provides a more compact description of "ggplot" objects than method str(). Here we provide a wrapper on R's str() with different default arguments. A summary does not directly describe how the different components of an R object are stored, while the structure does.

Examples

Run this code
# NOT RUN {
library(ggplot2)

p <- ggplot(mpg, aes(factor(year), (cty + hwy) / 2)) +
  geom_boxplot() +
  geom_point(color = "red") +
  facet_grid(. ~ class) +
  ggtitle("Example plot")

p

# str(p) vs. summary(p)
str(p, max.level = 1, size = FALSE)
summary(p)

# structure of p at 2 levels of nesting
str(p, max.level = 2)

# top level structure and size of p
str(p, max.level = 0)

# structure and size of p["data"]
str(p, components = "data")

# }

Run the code above in your browser using DataLab