The ggiraph is an htmlwidget and a ggplot2 extension. It allows ggplot graphics to be animated.
Animation is made with ggplot geometries that can understand three arguments:
Tooltip: a column of data-sets that contain tooltips to be displayed when the mouse is over elements.
Data_id: a column of data-sets that contain an ID to be associated with elements.
If it used within a shiny application, elements associated with an ID (data_id) can be selected and manipulated on client and server sides.
Before proceeding, please follow our short tutorial.
Look at the examples given and try to understand the logic behind them. Then, try to solve the exercises below by using R without looking at the answers. Then, check the solutions to check your answers.
Create a basic ggplot object of the mtcars data-set, choosing variables of your choice.
Create a scatter-plot of the object you just created by adding a tooltip.
Add the hover effect.
Create a crimes data frame.
Create an on-click event.
Add the on-click event. Connect every state with the link http://en.wikipedia.org/wiki/.
Change the http to https://en.wikipedia.org/wiki/U.S._state.
gg_crime <- ggplot(crimes, aes(x = Murder, y = Assault, color = UrbanPop )) +
aes( data_id = state, tooltip = state ), size = 3 ) +
scale_colour_gradient(low = “#999999”, high = “#FF3333”)
to an on-click plot.
Display the plot.
Change the spots’ color to orange.