Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R does ggplot2 have interactivity option?

I have some data that I'd like to put in a scatter plot and when I rollover the point on the chart I'd like to have a bubble popup and give some identifying info.

For instance if I had a data frame with a students name, height and weight, I'd like to plot height and weight on the x and y axis respectively. Then when I rollover an individual point on the plot a bubble would pop up with the students name.

There is a somewhat similar function used in a basic plot() called identify() but it requires clicking on the point and doesn't go away after I leave the point.

Here's a sample df and the plot/identify code:

> 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's an example after clicking on a few points:

enter image description here

Any suggestions?

like image 678
screechOwl Avatar asked Dec 07 '12 17:12

screechOwl


1 Answers

The HTKidentify and HWidentify functions in the TeachingDemos package allow for the creation of a scatter plot and having information pop up when you hover the mouse over a data point, the information goes away when you move to a new point. The first one requires Tk and the second one is only for windows and neither uses ggplot2 (but both are pure R code, so you may find a way to modify them to work with ggplot2 or other extensions).

like image 192
Greg Snow Avatar answered Oct 19 '22 23:10

Greg Snow