stat_debug_group {gginnards} | R 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
|
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
|
dbgfun.data , geom.dbgfun.data , geom.dbgfun.params |
A
functions used to summarise the |
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 |
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?
|
inherit.aes |
If |
... |
other arguments passed on to |
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()
ofdata
object- ncol
ncol()
ofdata
object- colnames
colnames()
ofdata
object- colclasses
class()
ofx
andy
columns indata
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()