The geometry is based on ggplot2::geom_violin(). See the documentation for those functions for more details.

geom_violin_interactive(...)

Arguments

...

arguments passed to base function, plus any of the interactive_parameters.

Details for interactive geom functions

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.

See also

Examples

# add interactive violin plot -------
library(ggplot2)
library(ggiraph)

p <- ggplot(mtcars, aes(factor(cyl), mpg)) +
  geom_violin_interactive(aes(fill = cyl, tooltip = cyl))
x <- girafe(ggobj = p)
#> Error in (function (mapping = NULL, data = NULL, stat = "ydensity", position = "dodge",     ..., trim = TRUE, bounds = c(-Inf, Inf), quantile.colour = NULL,     quantile.color = NULL, quantile.linetype = 0L, quantile.linewidth = NULL,     draw_quantiles = deprecated(), scale = "area", na.rm = FALSE,     orientation = NA, show.legend = NA, inherit.aes = TRUE) {    extra <- list()    if (lifecycle::is_present(draw_quantiles)) {        deprecate_soft0("4.0.0", what = "geom_violin(draw_quantiles)",             with = "geom_violin(quantiles.linetype)")        check_numeric(draw_quantiles)        stat <- validate_subclass(stat, "Stat", current_call(),             caller_env())        if ("quantiles" %in% stat$parameters()) {            extra$quantiles <- draw_quantiles        }        if (!is.null(quantile.linetype)) {            quantile.linetype <- max(quantile.linetype, 1)        }    }    quantile_gp <- list(colour = quantile.color %||% quantile.colour,         linetype = quantile.linetype, linewidth = quantile.linewidth)    layer(data = data, mapping = mapping, stat = stat, geom = GeomViolin,         position = position, show.legend = show.legend, inherit.aes = inherit.aes,         params = list2(trim = trim, scale = scale, na.rm = na.rm,             orientation = orientation, bounds = bounds, quantile_gp = quantile_gp,             !!!extra, ...))})(structure(list(fill = ~cyl), 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")))): Problem while converting geom to grob.
#>  Error occurred in the 1st layer.
#> Caused by error in `draw_panel()`:
#> ! unused argument (quantile_gp = list(NULL, 0, NULL))
if( interactive() ) print(x)

# Show quartiles
p2 <- ggplot(mtcars, aes(factor(cyl), mpg)) +
  geom_violin_interactive(aes(tooltip=after_stat(density)),
                          draw_quantiles = c(0.25, 0.5, 0.75))
x2 <- girafe(ggobj = p2)
#> Error in (function (mapping = NULL, data = NULL, stat = "ydensity", position = "dodge",     ..., trim = TRUE, bounds = c(-Inf, Inf), quantile.colour = NULL,     quantile.color = NULL, quantile.linetype = 0L, quantile.linewidth = NULL,     draw_quantiles = deprecated(), scale = "area", na.rm = FALSE,     orientation = NA, show.legend = NA, inherit.aes = TRUE) {    extra <- list()    if (lifecycle::is_present(draw_quantiles)) {        deprecate_soft0("4.0.0", what = "geom_violin(draw_quantiles)",             with = "geom_violin(quantiles.linetype)")        check_numeric(draw_quantiles)        stat <- validate_subclass(stat, "Stat", current_call(),             caller_env())        if ("quantiles" %in% stat$parameters()) {            extra$quantiles <- draw_quantiles        }        if (!is.null(quantile.linetype)) {            quantile.linetype <- max(quantile.linetype, 1)        }    }    quantile_gp <- list(colour = quantile.color %||% quantile.colour,         linetype = quantile.linetype, linewidth = quantile.linewidth)    layer(data = data, mapping = mapping, stat = stat, geom = GeomViolin,         position = position, show.legend = show.legend, inherit.aes = inherit.aes,         params = list2(trim = trim, scale = scale, na.rm = na.rm,             orientation = orientation, bounds = bounds, quantile_gp = quantile_gp,             !!!extra, ...))})(structure(list(), 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")), names = character(0)),     draw_quantiles = c(0.25, 0.5, 0.75)): Problem while converting geom to grob.
#>  Error occurred in the 1st layer.
#> Caused by error in `draw_panel()`:
#> ! unused argument (quantile_gp = list(NULL, 1, NULL))
if( interactive() ) print(x2)