The geometries are based on ggplot2::geom_bar() and ggplot2::geom_col(). See the documentation for those functions for more details.

geom_bar_interactive(...)

geom_col_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 bar -------
library(ggplot2)
library(ggiraph)

p <- ggplot(mpg, aes( x = class, tooltip = class,
        data_id = class ) ) +
  geom_bar_interactive()

x <- girafe(ggobj = p)
#> Error in (function (mapping = NULL, data = NULL, stat = "count", position = "stack",     ..., just = 0.5, lineend = "butt", linejoin = "mitre", na.rm = FALSE,     show.legend = NA, inherit.aes = TRUE) {    layer(mapping = mapping, data = data, geom = "bar", stat = stat,         position = position, show.legend = show.legend, inherit.aes = inherit.aes,         params = list2(na.rm = na.rm, just = just, lineend = lineend,             linejoin = linejoin, ...))})(): Problem while converting geom to grob.
#>  Error occurred in the 1st layer.
#> Caused by error in `draw_panel()`:
#> ! unused arguments (lineend = "butt", linejoin = "mitre")
if( interactive() ) print(x)

dat <- data.frame( name = c( "David", "Constance", "Leonie" ),
    gender = c( "Male", "Female", "Female" ),
    height = c(172, 159, 71 ) )
p <- ggplot(dat, aes( x = name, y = height, tooltip = gender,
                      data_id = name ) ) +
  geom_col_interactive()

x <- girafe(ggobj = p)
#> Error in (function (mapping = NULL, data = NULL, stat = "identity", position = "stack",     ..., just = 0.5, lineend = "butt", linejoin = "mitre", na.rm = FALSE,     show.legend = NA, inherit.aes = TRUE) {    layer(mapping = mapping, data = data, geom = "col", stat = stat,         position = position, show.legend = show.legend, inherit.aes = inherit.aes,         params = list2(na.rm = na.rm, just = just, lineend = lineend,             linejoin = linejoin, ...))})(): Problem while converting geom to grob.
#>  Error occurred in the 1st layer.
#> Caused by error in `draw_panel()`:
#> ! unused arguments (lineend = "butt", linejoin = "mitre")
if( interactive() ) print(x)

# an example with interactive guide ----
dat <- data.frame(
  name = c( "Guy", "Ginette", "David", "Cedric", "Frederic" ),
  gender = c( "Male", "Female", "Male", "Male", "Male" ),
  height = c(169, 160, 171, 172, 171 ) )
p <- ggplot(dat, aes( x = name, y = height, fill = gender,
                      data_id = name ) ) +
  geom_bar_interactive(stat = "identity") +
    scale_fill_manual_interactive(
      values = c(Male = "#0072B2", Female = "#009E73"),
      data_id = c(Female = "Female", Male = "Male"),
      tooltip = c(Male = "Male", Female = "Female")
    )
x <- girafe(ggobj = p)
#> Error in (function (mapping = NULL, data = NULL, stat = "count", position = "stack",     ..., just = 0.5, lineend = "butt", linejoin = "mitre", na.rm = FALSE,     show.legend = NA, inherit.aes = TRUE) {    layer(mapping = mapping, data = data, geom = "bar", stat = stat,         position = position, show.legend = show.legend, inherit.aes = inherit.aes,         params = list2(na.rm = na.rm, just = just, lineend = lineend,             linejoin = linejoin, ...))})(stat = "identity"): Problem while converting geom to grob.
#>  Error occurred in the 1st layer.
#> Caused by error in `draw_panel()`:
#> ! unused arguments (lineend = "butt", linejoin = "mitre")
if( interactive() ) print(x)