geom_debug | R Documentation |
The debug geom is used to print to the console a summary of the data being
received by geoms as input data
data frame.
geom_debug(
mapping = NULL,
data = NULL,
stat = "identity",
summary.fun = "head",
summary.fun.args = list(),
parse = NULL,
nudge_x = 0,
nudge_y = 0,
position = "identity",
na.rm = FALSE,
show.legend = FALSE,
inherit.aes = TRUE,
...
)
geom_debug_npc(
mapping = NULL,
data = NULL,
stat = "identity",
summary.fun = "head",
summary.fun.args = list(),
parse = NULL,
nudge_x = 0,
nudge_y = 0,
position = "identity",
na.rm = FALSE,
show.legend = FALSE,
inherit.aes = TRUE,
...
)
mapping |
Set of aesthetic mappings created by
|
data |
A data frame. If specified, overrides the default data frame defined at the top level of the plot. |
stat |
The statistical transformation to use on the data for this layer, as a string. |
summary.fun |
The name of a function as a character string (or a
function) to be used to summarize the |
summary.fun.args |
A list of additional arguments
to be passed to |
parse |
Ignored. Helps avoid warnings. |
nudge_x, nudge_y |
Horizontal and vertical adjustments to nudge the
starting position. The units for |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
other arguments passed on to
|
It can be useful when debugging the code of statistics or to learn how the stats and geoms work in 'ggplot2' (>= 2.0.0).
The intended use of this geometry is to help explore the data as
they are added to a plot layer. It is very unusual in that it does not
produce visible graphic output. It only returns a grid.null()
grob
(graphical object) when the plot is rendered. Also, differently to normal
geometries, it passes its data
input as argument to the first
parameter of the function passed as argument to summary.fun
. The
value returned by this function is then printed to the R console. If
summary.fun = NULL
, the whole data
object is printed.
Nudging with nudge_x
and nudge_y
behave as in
geom_text
. Arguments passed to position
are
obeyed. So the effects of positions are reflected in the data
object
printed or summarized to the R console. The argument passed to parse
is currently ignored.
Many aesthetics are defined as optional so that they are accepted silently
by geom_debug()
and handled by 'ggplot2' as usual.
If the argument passed to summary.fun()
is a character string, the
name will appear in the header of the printout. However, the function
must be available at the time the plot is rendered. If a function is
passed as argument, its definition will be saved as part of the "gg"
object.
The panel function of this geometry always returns a
nullGrob
, the legend is is also set to
nullGrob
. This geometry used for its text printing side
effect.
To access data, scales and grobs in a built ggplot, see
ggplot_build
.
# echo to the R console \code{data} as received by geoms
ggplot(mtcars, aes(cyl, mpg, color = factor(cyl))) +
geom_point() +
geom_debug()
ggplot(mtcars, aes(cyl, mpg, color = factor(cyl))) +
geom_point() +
geom_debug(summary.fun = "head", summary.fun.args = list(n = 3))
ggplot(mtcars, aes(cyl, mpg, color = factor(cyl))) +
geom_point() +
geom_debug(summary.fun = "nrow")
ggplot(mtcars, aes(cyl, mpg, color = factor(cyl))) +
geom_point() +
geom_debug(summary.fun = "attributes")
# echo to the R console \code{data} as received by geoms
ggplot(mtcars, aes(cyl, mpg, colour = factor(cyl))) +
stat_summary(fun.data = "mean_se") +
stat_summary(fun.data = "mean_se", geom = "debug", summary.fun = NULL)
# shape data is not passed to geometries or statistics
if (requireNamespace("sf", quietly = TRUE)) {
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot(data = nc) +
geom_sf(color = "darkblue", fill = "white") +
geom_debug()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.