I'm working on trying to create a translator of sorts from ggplot2 to d3 (animint package). There are a few aesthetics in d3 (tooltips, selectors, mouseover events) that are not available in ggplot2. In order to specify these aesthetics using ggplot2 syntax, I'm thinking we would need to create new aesthetics for these interactions.
I found a similar question on the ggplot2 mailing list from last year (
https://groups.google.com/forum/#!topic/ggplot2/kIS-sw4f7o0), but that was more than a year ago, and Hadley indicated that things might change after the "layers re-write".
> If you modify default_aes() in GeomPoint, it will do what you're looking
> for. You could do something like this:
> default_aes <- function(.) aes(shape=16, colour="black", size=2, fill =
> NA, alpha = 1, tooltip=NA)
>
> I don't know if this is the "right" way - maybe Hadley will weigh in.
I don't think there's any right way at the moment. Perhaps there will
be after the layers re-write.
Is there a "right" way to incorporate new aesthetics? Is there a way to do it without modifying each individual geom, as suggested in the other post? I'm mostly concerned with geoms that are linked to statistics, because a direct one-to-one mapping doesn't necessarily exist, so passing columns of a data frame through doesn't work. For example, with geom_histogram,
data <- data.frame(x=rnorm(100, 0, 1), x2 = rpois(100, 1))
library(ggplot2)
ggplot() + geom_histogram(data=data, aes(x=x, group=x2, fill=x2, tooltip=..count..))
where mousing over an individual box would show the number of data points contained within that box (ideally).
Thanks!