Does ggplot2 have interactivity?

I have some data that I would like to put in a scatter plot, and when I flipped a point on the chart, I would like to pop up a bubble and give some identifying information.

For example, if I had a data frame with a student name, height and weight, I would like to plot the height and weight on the x and y axis, respectively. Then, when I flip a single point on the plot, a bubble pops up with a student name.

There is some similar function used in the base plot() called identify() , but requires a click on the point and does not disappear after I left the point.

Here's an example df and a graph / code id:

 > dput(df1) structure(list(id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), var1 = c(0.469521932071075, 0.077109789242968, 0.076340542640537, 0.461061101639643, 0.347079795086756, 0.425340321380645, 0.738443679409102, 0.00931701785884798, 0.267918228404596, 0.722170797875151), var2 = c(0.265150599181652, 0.557858553016558, 0.715832461370155, 0.186717337928712, 0.626156869810075, 0.1359783844091, 0.67408229294233, 0.528320853365585, 0.241800826275721, 0.80992470192723 ), names = c("jim", "nancy", "suzy", "mark", "alex", "jen", "luz", "jeff", "paula", "amir")), .Names = c("id", "var1", "var2", "names" ), row.names = c(NA, -10L), class = "data.frame") plot(df1$var1, df1$var2);grid() identify(df1$var1, df1$var2, labels = df1$names) 

Here is an example after clicking a few dots:

enter image description here

Any suggestions?

+6
source share
1 answer

The HTKidentify and HWidentify in the TeachingDemos package allow you to create a scatter chart and display information when you hover over a data point, the information disappears when you move to a new point, the first requires Tk, and the second only for windows, and none of them uses ggplot2 ( but both are pure R code, so you can find a way to change them to work with ggplot2 or other extensions).

+6
source

All Articles