stat_debug_group: Print to console data received by statistics as input

View source: R/stat-debug.R

stat_debug_groupR Documentation

Print to console data received by statistics as input

Description

stat_debug_group and stat_debug_panel apply a function to data and, most importantly, echo to the R console their data input or a summary of it.

Usage

stat_debug_group(
  mapping = NULL,
  data = NULL,
  geom = "null",
  fun.data = "I",
  fun.data.args = list(),
  dbgfun.data = "head",
  dbgfun.data.args = list(),
  geom.dbgfun.data = "head",
  geom.dbgfun.data.args = list(),
  geom.dbgfun.params = NULL,
  geom.dbgfun.params.args = list(),
  dbgfun.print = "print",
  dbgfun.print.args = list(),
  position = "identity",
  na.rm = FALSE,
  show.legend = FALSE,
  inherit.aes = TRUE,
  ...
)

stat_debug_panel(
  mapping = NULL,
  data = NULL,
  geom = "null",
  fun.data = "I",
  fun.data.args = list(),
  dbgfun.data = "head",
  dbgfun.data.args = list(),
  geom.dbgfun.data = "head",
  geom.dbgfun.data.args = list(),
  geom.dbgfun.params = NULL,
  geom.dbgfun.params.args = list(),
  dbgfun.print = "print",
  dbgfun.print.args = list(),
  position = "identity",
  na.rm = FALSE,
  show.legend = FALSE,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

The aesthetic mapping, usually constructed with aes or aes_. Only needs to be set at the layer level if you are overriding the plot defaults.

data

A layer specific dataset - only needed if you want to override the plot defaults.

geom

The geometric object to use display the data

fun.data

A function taking a data frame as its first argument and returning a data frame. This function does the computations generating the value passed from the statistic to the downstream geometry.

fun.data.args

A named list of additional arguments to be passed to fun.data.

dbgfun.data, geom.dbgfun.data, geom.dbgfun.params

A functions used to summarise the data and parameters objects received as input by the statistic and geometry.

dbgfun.data.args, geom.dbgfun.data.args, geom.dbgfun.params.args

A named list of arguments.

dbgfun.print

A function used to print the summary of the data object received as input by the statistic, also visible to the geometry, and used by geom_debug().

dbgfun.print.args

A named list. Currently ignored!

position

The position adjustment to use for overlapping points on this layer

na.rm

a logical value indicating whether NA values should be stripped before the computation proceeds.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders.

...

other arguments passed on to layer. This can include aesthetics whose values you want to set, not map. See layer for more details.

Details

These stats are meant to be used for the side-effect of printing to the console the data object received as input by the compute_group() or compute_panel() function, or a summary of it. These data objects are the same as those received as input by any other statistics passed the same arguments. By default, the applied function is I(), the identity function.

In principle any geom can be passed as argument to override geom = "null". However, geom = "debug_panel" and geom = "debug_group" are treated as special cases and functions geom.dbgfun.data and geom.dbgfun.params, and lists geom.dbgfun.data.args and geom.dbgfun.params.args renamed and passed to the geometry. Arguments passed to these four formal parameters are not passed to other geometries.

Keep in mind that this stat sets default mappings only for the x and/or y aesthetics, additional mappings can be set using aes(), possibly together with after_stat().

Value

A copy of its data input, which is an object of class "data.frame" or inheriting from "data.frame".

Computed variables

x

x at centre of range

y

y at centre of range

nrow

nrow() of data object

ncol

ncol() of data object

colnames

colnames() of data object

colclasses

class() of x and y columns in data object

group

all distinct values in group as passed in data object

PANEL

all distinct values in PANEL as passed in data object

Examples

my.df <- data.frame(x = rep(1:10, 2),
                    y = rep(c(1,2), c(10,10)) + rnorm(20),
                    group = rep(c("A","B"), c(10,10)))

# by default head() is used to show the top rows of the data object
# and geom_null() to silence the data returned by the stat
ggplot(my.df, aes(x,y)) +
  geom_point() +
  stat_debug_group()

# geom_debug prints the data returned by the stat
ggplot(my.df, aes(x,y)) +
  geom_point() +
  stat_debug_group(geom = "debug_panel")

# geom_debug prints the data returned by the stat
ggplot(my.df, aes(x,y)) +
  geom_point() +
  stat_debug_group(geom = "debug_panel",
                   geom.dbgfun.params = "summary")

# to print only the the data returned by the stat
# we pass as summary function a function that always returns NULL
ggplot(my.df, aes(x,y)) +
  geom_point() +
  stat_debug_group(geom = "debug_panel",
                   dbgfun.data = function(x) {NULL})

ggplot(my.df, aes(x,y)) +
  geom_point() +
  stat_debug_group(aes(label = paste("group:", group)),
                   geom = "text")

# here we show all the data object
ggplot(my.df, aes(x,y)) +
  geom_point() +
  stat_debug_group(dbgfun.data = "I")

# with grouping
ggplot(my.df, aes(x,y, colour = group)) +
  geom_point() +
  stat_debug_group()

ggplot(my.df, aes(x,y, colour = group)) +
  geom_point() +
  stat_debug_panel()

ggplot(my.df, aes(x, y, colour = group)) +
  geom_point() +
  stat_debug_group(dbgfun.data = "nrow")

ggplot(my.df, aes(x, y)) +
  geom_point() +
  facet_wrap(~group) +
  stat_debug_group()

# by default head() is used to show the top rows of data object
ggplot(my.df, aes(group,y)) +
  geom_point() +
  stat_debug_group()


gginnards documentation built on May 29, 2024, 2:08 a.m.