View source: R/geom_bar_interactive.R
geom_bar_interactive | R Documentation |
The geometries are based on geom_bar()
and geom_col()
.
See the documentation for those functions for more details.
geom_bar_interactive(...)
geom_col_interactive(...)
... |
arguments passed to base function, plus any of the interactive_parameters. |
The interactive parameters can be supplied with two ways:
As aesthetics with the mapping argument (via 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.
girafe()
# 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)
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)
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)
if( interactive() ) print(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.