On 5/18/2013 5:56 AM, Ryan Hope wrote:
> I am working on a R package for eyetracking reasearch and in it I provide
> some functions to visual data with ggplot2. Some of the visualizations are
> stand alone plots but others work well as layers that could be combined
> with other plots. I've created some "custom" geoms by simply wrapping
> pre-existing geoms in a function so that I can transform in input into
> ggplot friendly arguments. This works fine for most cases but I have run
> into a few situations where I would like to combine 2 geoms into one. For
> example, I would like to do something like this:
>
> geom_grid <- function() {
> geom_hline() + geom_vline()
> }
geom_grid <- function() {
c(geom_hline(), geom_vline())
}
Or in a complete example:
geom_grid <- function(v = 0) {
c(geom_hline(yintercept=v), geom_vline(xintercept=v))
}
ggplot(data.frame(x=rnorm(20), y=rnorm(20)), aes(x,y)) +
geom_point() +
geom_grid() +
geom_grid(1)
> which obviously throws a "non-numeric argument to binary operator" error.
> The same thing goes for creating a function to set both x and y scales with
> one function. Is there an easy way to do this?
>
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University