Creating new aesthetics

57 views
Skip to first unread message

Susan Vander Plas

unread,
Jul 29, 2013, 11:37:36 AM7/29/13
to ggplo...@googlegroups.com
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!

Hadley Wickham

unread,
Jul 30, 2013, 11:15:35 AM7/30/13
to Susan Vander Plas, ggplo...@googlegroups.com
> 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).

I think, unfortunately, that you'd either need to rewrite each stat +
geom, or somehow finagle into an existing aesthetic.

Hadley

--
Chief Scientist, RStudio
http://had.co.nz/
Reply all
Reply to author
Forward
0 new messages