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)

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

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)
#> List of 9 #> $ data :Classes 'tbl_df', 'tbl' and 'data.frame': 234 obs. of 11 variables: #> $ layers :List of 2 #> $ scales :Classes 'ScalesList', 'ggproto', 'gg' <ggproto object: Class ScalesList, gg> #> add: function #> clone: function #> find: function #> get_scales: function #> has_scale: function #> input: function #> n: function #> non_position_scales: function #> scales: list #> super: <ggproto object: Class ScalesList, gg> #> $ mapping :List of 2 #> $ theme : list() #> $ coordinates:Classes 'CoordCartesian', 'Coord', 'ggproto', 'gg' <ggproto object: Class CoordCartesian, Coord, gg> #> aspect: function #> backtransform_range: function #> clip: on #> default: TRUE #> distance: function #> expand: TRUE #> is_free: function #> is_linear: function #> labels: function #> limits: list #> modify_scales: function #> range: function #> render_axis_h: function #> render_axis_v: function #> render_bg: function #> render_fg: function #> setup_data: function #> setup_layout: function #> setup_panel_params: function #> setup_params: function #> transform: function #> super: <ggproto object: Class CoordCartesian, Coord, gg> #> $ facet :Classes 'FacetGrid', 'Facet', 'ggproto', 'gg' <ggproto object: Class FacetGrid, Facet, gg> #> compute_layout: function #> draw_back: function #> draw_front: function #> draw_labels: function #> draw_panels: function #> finish_data: function #> init_scales: function #> map_data: function #> params: list #> setup_data: function #> setup_params: function #> shrink: TRUE #> train_scales: function #> vars: function #> super: <ggproto object: Class FacetGrid, Facet, gg> #> $ plot_env :<environment: 0x0000000022dea150> #> $ labels :List of 3
#> data: manufacturer, model, displ, year, cyl, trans, drv, cty, hwy, fl, #> class [234x11] #> mapping: x = ~factor(year), y = ~(cty + hwy)/2 #> faceting: <ggproto object: Class FacetGrid, Facet, gg> #> compute_layout: function #> draw_back: function #> draw_front: function #> draw_labels: function #> draw_panels: function #> finish_data: function #> init_scales: function #> map_data: function #> params: list #> setup_data: function #> setup_params: function #> shrink: TRUE #> train_scales: function #> vars: function #> super: <ggproto object: Class FacetGrid, Facet, gg> #> ----------------------------------- #> geom_boxplot: outlier.colour = NULL, outlier.fill = NULL, outlier.shape = 19, outlier.size = 1.5, outlier.stroke = 0.5, outlier.alpha = NULL, notch = FALSE, notchwidth = 0.5, varwidth = FALSE, na.rm = FALSE #> stat_boxplot: na.rm = FALSE #> position_dodge2 #> #> geom_point: na.rm = FALSE #> stat_identity: na.rm = FALSE #> position_identity #>
# structure of p at 2 levels of nesting str(p, max.level = 2)
#> Object size: 30.9 kB #> List of 9 #> $ data :Classes 'tbl_df', 'tbl' and 'data.frame': 234 obs. of 11 variables: #> ..$ manufacturer: chr [1:234] "audi" "audi" ... #> ..$ model : chr [1:234] "a4" "a4" ... #> ..$ displ : num [1:234] 1.8 1.8 2 2 2.8 ... #> ..$ year : int [1:234] 1999 1999 2008 2008 1999 ... #> ..$ cyl : int [1:234] 4 4 4 4 6 ... #> ..$ trans : chr [1:234] "auto(l5)" "manual(m5)" ... #> ..$ drv : chr [1:234] "f" "f" ... #> ..$ cty : int [1:234] 18 21 20 21 16 ... #> ..$ hwy : int [1:234] 29 29 31 30 26 ... #> ..$ fl : chr [1:234] "p" "p" ... #> ..$ class : chr [1:234] "compact" "compact" ... #> $ layers :List of 2 #> ..$ :Classes 'LayerInstance', 'Layer', 'ggproto', 'gg' <ggproto object: Class LayerInstance, Layer, gg> #> aes_params: list #> compute_aesthetics: function #> compute_geom_1: function #> compute_geom_2: function #> compute_position: function #> compute_statistic: function #> data: waiver #> draw_geom: function #> finish_statistics: function #> geom: <ggproto object: Class GeomBoxplot, Geom, gg> #> aesthetics: function #> default_aes: uneval #> draw_group: function #> draw_key: function #> draw_layer: function #> draw_panel: function #> extra_params: na.rm width #> handle_na: function #> non_missing_aes: #> optional_aes: #> parameters: function #> required_aes: x lower upper middle ymin ymax #> setup_data: function #> use_defaults: function #> super: <ggproto object: Class Geom, gg> #> geom_params: list #> inherit.aes: TRUE #> layer_data: function #> map_statistic: function #> mapping: NULL #> position: <ggproto object: Class PositionDodge2, PositionDodge, Position, gg> #> compute_layer: function #> compute_panel: function #> padding: 0.1 #> preserve: total #> required_aes: #> reverse: FALSE #> setup_data: function #> setup_params: function #> width: NULL #> super: <ggproto object: Class PositionDodge, Position, gg> #> print: function #> show.legend: NA #> stat: <ggproto object: Class StatBoxplot, Stat, gg> #> aesthetics: function #> compute_group: function #> compute_layer: function #> compute_panel: function #> default_aes: uneval #> extra_params: na.rm #> finish_layer: function #> non_missing_aes: weight #> parameters: function #> required_aes: y #> retransform: TRUE #> setup_data: function #> setup_params: function #> super: <ggproto object: Class Stat, gg> #> stat_params: list #> super: <ggproto object: Class Layer, gg> #> ..$ :Classes 'LayerInstance', 'Layer', 'ggproto', 'gg' <ggproto object: Class LayerInstance, Layer, gg> #> aes_params: list #> compute_aesthetics: function #> compute_geom_1: function #> compute_geom_2: function #> compute_position: function #> compute_statistic: function #> data: waiver #> draw_geom: function #> finish_statistics: function #> geom: <ggproto object: Class GeomPoint, Geom, gg> #> aesthetics: function #> default_aes: uneval #> draw_group: function #> draw_key: function #> draw_layer: function #> draw_panel: function #> extra_params: na.rm #> handle_na: function #> non_missing_aes: size shape colour #> optional_aes: #> parameters: function #> required_aes: x y #> setup_data: function #> use_defaults: function #> super: <ggproto object: Class Geom, gg> #> geom_params: list #> inherit.aes: TRUE #> layer_data: function #> map_statistic: function #> mapping: NULL #> position: <ggproto object: Class PositionIdentity, Position, gg> #> compute_layer: function #> compute_panel: function #> required_aes: #> setup_data: function #> setup_params: function #> super: <ggproto object: Class Position, gg> #> print: function #> show.legend: NA #> stat: <ggproto object: Class StatIdentity, Stat, gg> #> aesthetics: function #> compute_group: function #> compute_layer: function #> compute_panel: function #> default_aes: uneval #> extra_params: na.rm #> finish_layer: function #> non_missing_aes: #> parameters: function #> required_aes: #> retransform: TRUE #> setup_data: function #> setup_params: function #> super: <ggproto object: Class Stat, gg> #> stat_params: list #> super: <ggproto object: Class Layer, gg> #> $ scales :Classes 'ScalesList', 'ggproto', 'gg' <ggproto object: Class ScalesList, gg> #> add: function #> clone: function #> find: function #> get_scales: function #> has_scale: function #> input: function #> n: function #> non_position_scales: function #> scales: list #> super: <ggproto object: Class ScalesList, gg> #> $ mapping :List of 2 #> ..$ x: language ~factor(year) #> ..$ y: language ~(cty + hwy)/2 #> $ theme : list() #> $ coordinates:Classes 'CoordCartesian', 'Coord', 'ggproto', 'gg' <ggproto object: Class CoordCartesian, Coord, gg> #> aspect: function #> backtransform_range: function #> clip: on #> default: TRUE #> distance: function #> expand: TRUE #> is_free: function #> is_linear: function #> labels: function #> limits: list #> modify_scales: function #> range: function #> render_axis_h: function #> render_axis_v: function #> render_bg: function #> render_fg: function #> setup_data: function #> setup_layout: function #> setup_panel_params: function #> setup_params: function #> transform: function #> super: <ggproto object: Class CoordCartesian, Coord, gg> #> $ facet :Classes 'FacetGrid', 'Facet', 'ggproto', 'gg' <ggproto object: Class FacetGrid, Facet, gg> #> compute_layout: function #> draw_back: function #> draw_front: function #> draw_labels: function #> draw_panels: function #> finish_data: function #> init_scales: function #> map_data: function #> params: list #> setup_data: function #> setup_params: function #> shrink: TRUE #> train_scales: function #> vars: function #> super: <ggproto object: Class FacetGrid, Facet, gg> #> $ plot_env :<environment: 0x0000000022dea150> #> $ labels :List of 3 #> ..$ title: chr "Example plot" #> ..$ x : chr "factor(year)" #> ..$ y : chr "(cty + hwy)/2"
# top level structure and size of p str(p, max.level = 0)
#> Object size: 30.9 kB #> List of 9
# structure and size of p["data"] str(p, components = "data")
#> Object size: 24.1 kB #> List of 1 #> $ data:Classes 'tbl_df', 'tbl' and 'data.frame': 234 obs. of 11 variables: