Print to console data received by the compute panel function.
Source:R/stat-debug-panel.R
stat_debug_panel.Rd
stat_debug
reports all distinct values in group
and PANEL
, and nrow
, ncol
and the names of the columns
or variables, and the class of x and y for each panel in a ggplot as passed
to the compute_panel
function in the ggproto
object.
Arguments
- mapping
The aesthetic mapping, usually constructed with
aes
oraes_
. 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
- summary.fun, geom.summary.fun
A function used to print the
data
object received as input.- summary.fun.args, geom.summary.fun.args
A named list.
- 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, andTRUE
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. Seelayer
for more details.
Value
A tibble with a summary of the data
received, which is not
printed by default using geom_null()
. Can be printed by passing
geom = "debug"
.
Details
This stat is meant to be used for the side-effect of printing to the
console the data
object received as input by the
compute_panel()
function, or a summary of it. This is the same as
for any other statistics passed the same arguments (including defaults that
may need to be overridden if they differ).
In principle any geom can be passed as argument to override "null"
.
Keep in mind that this stat sets default mappings only for the x and
y aesthetics: geom_debug()
and geom_text()
are
useful.
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
See also
Other diagnosis functions:
stat_debug_group()
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 data object
# and geom_null() to silence the data returned by the stat
ggplot(my.df, aes(x,y)) +
geom_point() +
stat_debug_panel()
#> [1] "Summary (head) of input 'data' to 'compute_panel()':"
#> x y PANEL group
#> 1 1 0.2802629 1 -1
#> 2 2 1.1033508 1 -1
#> 3 3 1.6036208 1 -1
#> 4 4 1.1236823 1 -1
#> 5 5 0.2729408 1 -1
#> 6 6 0.9828729 1 -1
# geom_debug prints the data returned by the stat
ggplot(my.df, aes(x,y)) +
geom_point() +
stat_debug_panel(geom = "debug")
#> [1] "Summary (head) of input 'data' to 'compute_panel()':"
#> x y PANEL group
#> 1 1 0.2802629 1 -1
#> 2 2 1.1033508 1 -1
#> 3 3 1.6036208 1 -1
#> 4 4 1.1236823 1 -1
#> 5 5 0.2729408 1 -1
#> 6 6 0.9828729 1 -1
#> [1] "Input 'data' to 'draw_panel()':"
#> PANEL x y nrow ncol colnames class.x class.y groups
#> 1 1 5.5 1.455193 20 4 x, y, PANEL, group numeric numeric -1
# 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_panel(geom = "debug",
summary.fun = function(x) {NULL})
#> [1] "Input 'data' to 'draw_panel()':"
#> PANEL x y nrow ncol colnames class.x class.y groups
#> 1 1 5.5 1.455193 20 4 x, y, PANEL, group numeric numeric -1
ggplot(my.df, aes(x,y)) +
geom_point() +
stat_debug_panel(aes(label = sprintf("nrow = %i, ncol = %i, colnames: %s",
after_stat(nrow),
after_stat(ncol),
after_stat(colnames))),
geom = "text")
#> [1] "Summary (head) of input 'data' to 'compute_panel()':"
#> x y PANEL group
#> 1 1 0.2802629 1 -1
#> 2 2 1.1033508 1 -1
#> 3 3 1.6036208 1 -1
#> 4 4 1.1236823 1 -1
#> 5 5 0.2729408 1 -1
#> 6 6 0.9828729 1 -1
# here we show all the data object
ggplot(my.df, aes(x,y)) +
geom_point() +
stat_debug_panel(summary.fun = NULL)
#> [1] "Input 'data' to 'compute_panel()':"
#> x y PANEL group
#> 1 1 0.2802629 1 -1
#> 2 2 1.1033508 1 -1
#> 3 3 1.6036208 1 -1
#> 4 4 1.1236823 1 -1
#> 5 5 0.2729408 1 -1
#> 6 6 0.9828729 1 -1
#> 7 7 1.0808861 1 -1
#> 8 8 -0.3463575 1 -1
#> 9 9 0.8375301 1 -1
#> 10 10 1.4856974 1 -1
#> 11 1 3.1336841 1 -1
#> 12 2 2.7768047 1 -1
#> 13 3 1.2787715 1 -1
#> 14 4 2.1399029 1 -1
#> 15 5 1.8482084 1 -1
#> 16 6 3.2567427 1 -1
#> 17 7 1.8708172 1 -1
#> 18 8 1.6087301 1 -1
#> 19 9 1.7087974 1 -1
#> 20 10 1.7378782 1 -1
ggplot(my.df, aes(x,y)) +
geom_point() +
stat_debug_panel(summary.fun = "nrow")
#> [1] "Summary (nrow) of input 'data' to 'compute_panel()':"
#> [1] 20
# with grouping
ggplot(my.df, aes(x,y, colour = group)) +
geom_point() +
stat_debug_panel(summary.fun = NULL)
#> [1] "Input 'data' to 'compute_panel()':"
#> x y colour PANEL group
#> 1 1 0.2802629 A 1 1
#> 2 2 1.1033508 A 1 1
#> 3 3 1.6036208 A 1 1
#> 4 4 1.1236823 A 1 1
#> 5 5 0.2729408 A 1 1
#> 6 6 0.9828729 A 1 1
#> 7 7 1.0808861 A 1 1
#> 8 8 -0.3463575 A 1 1
#> 9 9 0.8375301 A 1 1
#> 10 10 1.4856974 A 1 1
#> 11 1 3.1336841 B 1 2
#> 12 2 2.7768047 B 1 2
#> 13 3 1.2787715 B 1 2
#> 14 4 2.1399029 B 1 2
#> 15 5 1.8482084 B 1 2
#> 16 6 3.2567427 B 1 2
#> 17 7 1.8708172 B 1 2
#> 18 8 1.6087301 B 1 2
#> 19 9 1.7087974 B 1 2
#> 20 10 1.7378782 B 1 2
ggplot(my.df, aes(x,y)) +
geom_point() +
facet_wrap(~group) +
stat_debug_panel()
#> [1] "Summary (head) of input 'data' to 'compute_panel()':"
#> x y PANEL group
#> 1 1 0.2802629 1 -1
#> 2 2 1.1033508 1 -1
#> 3 3 1.6036208 1 -1
#> 4 4 1.1236823 1 -1
#> 5 5 0.2729408 1 -1
#> 6 6 0.9828729 1 -1
#> [1] "Summary (head) of input 'data' to 'compute_panel()':"
#> x y PANEL group
#> 1 1 3.133684 2 -1
#> 2 2 2.776805 2 -1
#> 3 3 1.278772 2 -1
#> 4 4 2.139903 2 -1
#> 5 5 1.848208 2 -1
#> 6 6 3.256743 2 -1
# by default head() is used to show the top rows of data object
ggplot(my.df, aes(group,y)) +
geom_point() +
stat_debug_panel()
#> [1] "Summary (head) of input 'data' to 'compute_panel()':"
#> x y PANEL group
#> 1 1 0.2802629 1 1
#> 2 1 1.1033508 1 1
#> 3 1 1.6036208 1 1
#> 4 1 1.1236823 1 1
#> 5 1 0.2729408 1 1
#> 6 1 0.9828729 1 1