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.
# 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
)
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.
ggplot Plot object with embedded data.
accept additional parameter arguments
integer Maximum depth of recursion (of lists within lists ...) to be printed.
Vector of components to print, as indexes into
object
.
integer Approximate maximum length allowed when showing the first few values of a vector.
integer Maximum number of components to show of any list that will be described.
logical Flag, determining whether a description of attributes will be shown.
character String to be used for separating list components.
numeric current nesting level in the recursive calls to
str()
.
character String used for each level of indentation.
logical Flag, should the size of the object in bytes be printed?
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.
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)
summary(p) # from pacakge 'ggplot2'
# structure of p at 2 levels of nesting
str(p, max.level = 2, size = FALSE)
# top level structure and size of p
str(p, max.level = 0)
# names of ggplot members
names(p)
# structure and size of p["data"]
str(p, max.level = 2, components = "data")
# structure and size of p["layers"]
str(p, max.level = 1, components = "layers")
Run the code above in your browser using DataLab