Would it be possible to have ggplot2 handle this
ggplot() + c()
by doing nothing rather than giving a cryptic error? It think it
would only take adding an extra case to "+.ggplot" <- function(...)
before the last 'else' block.
6813a6814,6816
> } else if(class(object) == "NULL"){
> set_last_plot(p)
> p
This naturally comes up for example,
add_stuff_to_plot <- function (p, layers=NULL, scales=NULL,
facets=NULL, coord=NULL, options=NULL ){
# do stuff with each of the layers, scales, facets, coord and options...
...
p <- p + layers
...
p <- p + scales
...
}
There may be other ways of doing this (ie only add it if it actually
contains an object), but I don't think this is totally unreasonable as
it is. Depending on the philosophy of the project, I could see either
giving a warning/error that what was passed in was not allowed or
simply assuming the user knew what was going on and do something
sensible (ie just return the cloned ggplot object), but giving the
error
Error in switch(object$class(), layer = { : attempt to apply non-function
is frustrating because it doesn't give much indication about what went
wrong without digging through the ggplot2 code.
Best,
Matt
PS maybe "+.ggplot" could also handle when class(object)== "logical"
more elegantly as well. Thanks!
Both features there now in the development version.
Hadley
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
add_stuff_to_plot <- function (p, layers=NULL, scales=NULL,
facets=NULL, coord=NULL, options=NULL ){
# do stuff with each of the layers, scales, facets, coord and options...
...
if(!is.null(layers)){
p <- p + layers
}
...
if(!is.null(scales)){
p <- p + scales
}
...
}
--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University
Looking to arrange a meeting? Check my public calendar:
http://tr.im/mikes_public_calendar
~ Certainty is folly... I think. ~