Custom animation effects

With ggiraph, you can custom tooltip style and mouse hover effect. This requires usage of css.

Tooltip position

Argument tooltip_offx and tooltip_offy are used to offset tooltip position.

By default offset is 10 pixels horizontally to the mouse position (tooltip_offx=10) and 0 pixels vertically (tooltip_offx=10).

dataset <- mtcars
dataset$carname <- row.names(dataset)
gg_point_1 <- ggplot(dataset, aes(x = disp, y = qsec, tooltip = carname, data_id = carname, color= wt) ) + 

# htmlwidget call
ggiraph(code = {print(gg_point_1)}, tooltip_offx = 20, tooltip_offy = -10 )

Tooltip style

ggiraph function has an argument named tooltip_extra_css. It can be used to add css declarations that will be used to customize tooltip rendering.

Each css declaration includes a property name and an associated value, property name and value are separated by a colon, it always ends with a semicolon. For example color:gray;text-align:center;. Common properties are :

Tooltip opacity can be defined with argument tooltip_opacity (default to 0.9).

Let’s custom tooltip as:

tooltip_css <- "background-color:transparent;font-style:italic;"

Now print the ggiraph:

ggiraph(code = {print(gg_point_1)}, tooltip_extra_css = tooltip_css )

Now, let’s add a white rectangle with round borders to make it less crude and few other details:

tooltip_css <- "background-color:white;font-style:italic;padding:10px;border-radius:10px 20px 10px 20px;"

ggiraph(code = {print(gg_point_1)}, tooltip_extra_css = tooltip_css, tooltip_opacity = .75 )

Do not surround tooltip_extra_css value by curly braces, ggiraph is taking care of that.

Hover effects

Hover effects occured when mouse is over elements that have data-id attribute (resulting from using argument data_id in interactive geom functions). It will modify SVG elements rendering only when mouse will be over an element.

Effect can be configured with hover_css argument the same way tooltip_extra_css is used for customizing tooltip rendering.

css here is relative to SVG elements. SVG attributes are listed here. Common properties are:

To fill elements in red:

ggiraph(code = {print(gg_point_1)}, hover_css = "fill:red;r:10pt;" )


You can activate zoom; set zoom_max (maximum zoom factor) to a value greater than 1.

ggiraph(code = print(gg_point_1 + theme_linedraw()), zoom_max = 5)