| stat_summary_address {ggip} | R Documentation |
Summarize IP addresses on a heatmap
Description
Addresses are grouped into networks determined by the pixel_prefix argument
of coord_ip(). Then the z values are summarized with summary function fun.
Usage
stat_summary_address(
mapping = NULL,
data = NULL,
...,
fun = NULL,
fun.args = list(),
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
Arguments
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
... |
Other arguments passed on to |
fun |
Summary function (see section below for details). If |
fun.args |
A list of extra arguments to pass to |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
Aesthetics
stat_summary_address() understands the following aesthetics (required
aesthetics are in bold):
-
ip: Anip_addresscolumn -
z: Value passed to the summary function (required iffunis used) -
fill: Default isafter_stat(value) -
alpha
Computed variables
The following variables are available to after_stat():
-
value: Value of summary statistic -
count: Number of observations
Summary function
The data might contain multiple rows per pixel of the heatmap, so a summary
function reduces this information to a single value to display.
This function receives the data column specified by the z aesthetic
and also receives arguments specified by fun.args.
The fun argument can be specified in multiple ways:
NULLIf no summary function is provided, the number of observations is computed. In this case, you don't need to specify the
zaesthetic, and the computed variablesvalueandcountwill be equal.- string
The name of an existing function (e.g.
fun = "mean").- function
Either provide an existing function (e.g.
fun = mean) or define a new function (e.g.fun = function(x) sum(x^2)).- formula
A function can also be created from a formula. This uses
.xas the summarized variable (e.g.fun = ~ sum(.x^2)).
Examples
dat <- data.frame(
ip = sample_ipv4(10000),
weight = runif(10000)
)
p <- ggplot(dat, aes(ip = ip)) +
coord_ip() +
theme_ip_light()
# simple count of observations
p +
stat_summary_address() +
scale_fill_viridis_c(trans = "log2", na.value = "black", guide = "none")
# compute mean weight
p +
stat_summary_address(aes(z = weight), fun = ~ mean(.x)) +
scale_fill_viridis_c(na.value = "black", guide = "none")