7 Advanced customization
<- ggplot(
p1 data = diamonds,
mapping = aes(x = color, fill = cut, data_id = cut)) +
geom_bar_interactive(
aes(tooltip = sprintf("%s: %.0f", fill, after_stat(count))),
size = 3)
7.1 Controling svg identifier
It is possible to control the value of the SVG ID produced. In this case, the value must be assigned to the canvas_id
argument in the call to girafe()
which will be passed to the ggiraph::dsvg()
function.
girafe(ggobj = p1, canvas_id = "myid")
7.2 Adding attributes to interactive elements
Adding attributes to interactive elements is an advanced option that can be used to add a class name or any attribute.
<- ggplot(
p1 data = diamonds,
mapping = aes(x = color, fill = cut, data_id = cut)) +
geom_bar_interactive(
aes(tooltip = sprintf("%s: %.0f", fill, after_stat(count))),
size = 3, `data-blah`="myclass", extra_interactive_params = c("data-blah"),
onclick = "alert(this.getAttribute(\"data-blah\"));")
girafe(ggobj = p1)