The geometry is based on ggplot2::geom_boxplot().
See the documentation for that function for more details.
geom_boxplot_interactive(...)arguments passed to base function, plus any of the interactive_parameters.
You can supply interactive parameters for the outlier points by prefixing them
with outlier. prefix. For example: aes(outlier.tooltip = 'bla', outlier.data_id = 'blabla').
IMPORTANT: when supplying outlier interactive parameters,
the correct group aesthetic must be also supplied. Otherwise the default group calculation
will be incorrect, which will result in an incorrect plot.
The interactive parameters can be supplied with two ways:
As aesthetics with the mapping argument (via ggplot2::aes()).
In this way they can be mapped to data columns and apply to a set of geometries.
As plain arguments into the geom_*_interactive function. In this way they can be set to a scalar value.
# add interactive boxplot -------
library(ggplot2)
library(ggiraph)
p <- ggplot(mpg, aes(x = class, y = hwy, tooltip = class)) +
geom_boxplot_interactive()
x <- girafe(ggobj = p)
#> Error in (function (mapping = NULL, data = NULL, stat = "boxplot", position = "dodge2", ..., outliers = TRUE, outlier.colour = NULL, outlier.color = NULL, outlier.fill = NULL, outlier.shape = NULL, outlier.size = NULL, outlier.stroke = 0.5, outlier.alpha = NULL, whisker.colour = NULL, whisker.color = NULL, whisker.linetype = NULL, whisker.linewidth = NULL, staple.colour = NULL, staple.color = NULL, staple.linetype = NULL, staple.linewidth = NULL, median.colour = NULL, median.color = NULL, median.linetype = NULL, median.linewidth = NULL, box.colour = NULL, box.color = NULL, box.linetype = NULL, box.linewidth = NULL, notch = FALSE, notchwidth = 0.5, staplewidth = 0, varwidth = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE) { if (is.character(position)) { if (varwidth == TRUE) position <- position_dodge2(preserve = "single") } else { if (identical(position$preserve, "total") & varwidth == TRUE) { cli::cli_warn("Can't preserve total widths when {.code varwidth = TRUE}.") position$preserve <- "single" } } outlier_gp <- list(colour = outlier.color %||% outlier.colour, fill = outlier.fill, shape = outlier.shape, size = outlier.size, stroke = outlier.stroke, alpha = outlier.alpha) whisker_gp <- list(colour = whisker.color %||% whisker.colour, linetype = whisker.linetype, linewidth = whisker.linewidth) staple_gp <- list(colour = staple.color %||% staple.colour, linetype = staple.linetype, linewidth = staple.linewidth) median_gp <- list(colour = median.color %||% median.colour, linetype = median.linetype, linewidth = median.linewidth) box_gp <- list(colour = box.color %||% box.colour, linetype = box.linetype, linewidth = box.linewidth) check_number_decimal(staplewidth) check_bool(outliers) layer(data = data, mapping = mapping, stat = stat, geom = GeomBoxplot, position = position, show.legend = show.legend, inherit.aes = inherit.aes, params = list2(outliers = outliers, outlier_gp = outlier_gp, whisker_gp = whisker_gp, staple_gp = staple_gp, median_gp = median_gp, box_gp = box_gp, notch = notch, notchwidth = notchwidth, staplewidth = staplewidth, varwidth = varwidth, na.rm = na.rm, orientation = orientation, ...))})(stat = <environment>): Problem while converting geom to grob.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `draw_group()`:
#> ! unused arguments (outlier_gp = list(NULL, NULL, NULL, NULL, 0.5, NULL), whisker_gp = list(NULL, NULL, NULL), staple_gp = list(NULL, NULL, NULL), median_gp = list(NULL, NULL, NULL), box_gp = list(NULL, NULL, NULL))
if (interactive()) print(x)
p <- ggplot(mpg) +
geom_boxplot_interactive(
aes(
x = drv, y = hwy,
fill = class,
data_id = class,
tooltip = after_stat({
paste0(
"class: ", .data$fill,
"\nQ1: ", prettyNum(.data$lower),
"\nQ3: ", prettyNum(.data$upper),
"\nmedian: ", prettyNum(.data$middle)
)
})
),
outlier.colour = "red"
) +
guides(fill = "none") +
theme_minimal()
x <- girafe(ggobj = p)
#> Error in (function (mapping = NULL, data = NULL, stat = "boxplot", position = "dodge2", ..., outliers = TRUE, outlier.colour = NULL, outlier.color = NULL, outlier.fill = NULL, outlier.shape = NULL, outlier.size = NULL, outlier.stroke = 0.5, outlier.alpha = NULL, whisker.colour = NULL, whisker.color = NULL, whisker.linetype = NULL, whisker.linewidth = NULL, staple.colour = NULL, staple.color = NULL, staple.linetype = NULL, staple.linewidth = NULL, median.colour = NULL, median.color = NULL, median.linetype = NULL, median.linewidth = NULL, box.colour = NULL, box.color = NULL, box.linetype = NULL, box.linewidth = NULL, notch = FALSE, notchwidth = 0.5, staplewidth = 0, varwidth = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE) { if (is.character(position)) { if (varwidth == TRUE) position <- position_dodge2(preserve = "single") } else { if (identical(position$preserve, "total") & varwidth == TRUE) { cli::cli_warn("Can't preserve total widths when {.code varwidth = TRUE}.") position$preserve <- "single" } } outlier_gp <- list(colour = outlier.color %||% outlier.colour, fill = outlier.fill, shape = outlier.shape, size = outlier.size, stroke = outlier.stroke, alpha = outlier.alpha) whisker_gp <- list(colour = whisker.color %||% whisker.colour, linetype = whisker.linetype, linewidth = whisker.linewidth) staple_gp <- list(colour = staple.color %||% staple.colour, linetype = staple.linetype, linewidth = staple.linewidth) median_gp <- list(colour = median.color %||% median.colour, linetype = median.linetype, linewidth = median.linewidth) box_gp <- list(colour = box.color %||% box.colour, linetype = box.linetype, linewidth = box.linewidth) check_number_decimal(staplewidth) check_bool(outliers) layer(data = data, mapping = mapping, stat = stat, geom = GeomBoxplot, position = position, show.legend = show.legend, inherit.aes = inherit.aes, params = list2(outliers = outliers, outlier_gp = outlier_gp, whisker_gp = whisker_gp, staple_gp = staple_gp, median_gp = median_gp, box_gp = box_gp, notch = notch, notchwidth = notchwidth, staplewidth = staplewidth, varwidth = varwidth, na.rm = na.rm, orientation = orientation, ...))})(structure(list(x = ~drv, y = ~hwy, fill = ~class), class = c("ggplot2::mapping", "uneval", "gg", "S7_object"), S7_class = structure(function (x = list(), ..., env = globalenv()) { warn_dots_empty() check_object(x, is.list, "a {.cls list}") x <- lapply(x, new_aesthetic, env = env) x <- S7::new_object(x) class(x) <- union(c("ggplot2::mapping", "uneval"), class(x)) x}, name = "mapping", parent = structure(list(class = "gg", constructor = function (.data) { stop(sprintf("S3 class <%s> doesn't have a constructor", class[[1]]), call. = FALSE)}, validator = NULL), class = "S7_S3_class"), package = "ggplot2", properties = list(), abstract = FALSE, constructor = function (x = list(), ..., env = globalenv()) { warn_dots_empty() check_object(x, is.list, "a {.cls list}") x <- lapply(x, new_aesthetic, env = env) x <- S7::new_object(x) class(x) <- union(c("ggplot2::mapping", "uneval"), class(x)) x}, class = c("S7_class", "S7_object"))), outlier.colour = "red", stat = <environment>): Problem while converting geom to grob.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `draw_group()`:
#> ! unused arguments (outlier_gp = list("red", NULL, NULL, NULL, 0.5, NULL), whisker_gp = list(NULL, NULL, NULL), staple_gp = list(NULL, NULL, NULL), median_gp = list(NULL, NULL, NULL), box_gp = list(NULL, NULL, NULL))
if (interactive()) print(x)
p <- ggplot(mpg) +
geom_boxplot_interactive(
aes(
x = drv, y = hwy,
fill = class, group = paste(drv, class),
data_id = class,
tooltip = after_stat({
paste0(
"class: ", .data$fill,
"\nQ1: ", prettyNum(.data$lower),
"\nQ3: ", prettyNum(.data$upper),
"\nmedian: ", prettyNum(.data$middle)
)
}),
outlier.tooltip = paste(
"I am an outlier!\nhwy:", hwy, "\ndrv:", drv, "\nclass:", class
)
),
outlier.colour = "red"
) +
guides(fill = "none") +
theme_minimal()
x <- girafe(ggobj = p)
#> Error in (function (mapping = NULL, data = NULL, stat = "boxplot", position = "dodge2", ..., outliers = TRUE, outlier.colour = NULL, outlier.color = NULL, outlier.fill = NULL, outlier.shape = NULL, outlier.size = NULL, outlier.stroke = 0.5, outlier.alpha = NULL, whisker.colour = NULL, whisker.color = NULL, whisker.linetype = NULL, whisker.linewidth = NULL, staple.colour = NULL, staple.color = NULL, staple.linetype = NULL, staple.linewidth = NULL, median.colour = NULL, median.color = NULL, median.linetype = NULL, median.linewidth = NULL, box.colour = NULL, box.color = NULL, box.linetype = NULL, box.linewidth = NULL, notch = FALSE, notchwidth = 0.5, staplewidth = 0, varwidth = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE) { if (is.character(position)) { if (varwidth == TRUE) position <- position_dodge2(preserve = "single") } else { if (identical(position$preserve, "total") & varwidth == TRUE) { cli::cli_warn("Can't preserve total widths when {.code varwidth = TRUE}.") position$preserve <- "single" } } outlier_gp <- list(colour = outlier.color %||% outlier.colour, fill = outlier.fill, shape = outlier.shape, size = outlier.size, stroke = outlier.stroke, alpha = outlier.alpha) whisker_gp <- list(colour = whisker.color %||% whisker.colour, linetype = whisker.linetype, linewidth = whisker.linewidth) staple_gp <- list(colour = staple.color %||% staple.colour, linetype = staple.linetype, linewidth = staple.linewidth) median_gp <- list(colour = median.color %||% median.colour, linetype = median.linetype, linewidth = median.linewidth) box_gp <- list(colour = box.color %||% box.colour, linetype = box.linetype, linewidth = box.linewidth) check_number_decimal(staplewidth) check_bool(outliers) layer(data = data, mapping = mapping, stat = stat, geom = GeomBoxplot, position = position, show.legend = show.legend, inherit.aes = inherit.aes, params = list2(outliers = outliers, outlier_gp = outlier_gp, whisker_gp = whisker_gp, staple_gp = staple_gp, median_gp = median_gp, box_gp = box_gp, notch = notch, notchwidth = notchwidth, staplewidth = staplewidth, varwidth = varwidth, na.rm = na.rm, orientation = orientation, ...))})(structure(list(x = ~drv, y = ~hwy, fill = ~class, group = ~paste(drv, class)), class = c("ggplot2::mapping", "uneval", "gg", "S7_object"), S7_class = structure(function (x = list(), ..., env = globalenv()) { warn_dots_empty() check_object(x, is.list, "a {.cls list}") x <- lapply(x, new_aesthetic, env = env) x <- S7::new_object(x) class(x) <- union(c("ggplot2::mapping", "uneval"), class(x)) x}, name = "mapping", parent = structure(list(class = "gg", constructor = function (.data) { stop(sprintf("S3 class <%s> doesn't have a constructor", class[[1]]), call. = FALSE)}, validator = NULL), class = "S7_S3_class"), package = "ggplot2", properties = list(), abstract = FALSE, constructor = function (x = list(), ..., env = globalenv()) { warn_dots_empty() check_object(x, is.list, "a {.cls list}") x <- lapply(x, new_aesthetic, env = env) x <- S7::new_object(x) class(x) <- union(c("ggplot2::mapping", "uneval"), class(x)) x}, class = c("S7_class", "S7_object"))), outlier.colour = "red", stat = <environment>): Problem while converting geom to grob.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `draw_group()`:
#> ! unused arguments (outlier_gp = list("red", NULL, NULL, NULL, 0.5, NULL), whisker_gp = list(NULL, NULL, NULL), staple_gp = list(NULL, NULL, NULL), median_gp = list(NULL, NULL, NULL), box_gp = list(NULL, NULL, NULL))
if (interactive()) print(x)