[R] ggplot: adding layer using different data, groups and also controlling appearance
h.wickham at gmail.com
Thu Sep 25 03:03:05 CEST 2008
On Wed, Sep 24, 2008 at 7:57 PM, <rmailbox at justemail.net> wrote:
> I have a more complicated function I am trying to write, but I run in to a problem when I want to
> add something to the plot from more than one data set while simultaneously controlling the
> appearance of the additional layer.
> # Toy data:
> foo <- data.frame ( x = 1:4, y = 4:1 , membership = c( "A", "A", "B", "B" ) )
> bar <- data.frame ( x = 1:4 + 1 , y = 4:1 + 1, membership = rep ( "C", 4 ) )
> # This works, and produces a sensible (unified!) legend:
> foo.gg <- ggplot ( mapping = aes ( x = x, y = y , colour = membership ) )
> foo.gg <- foo.gg + geom_point(data = foo)
> foobar.gg <- foo.gg + geom_point ( data = bar ) # works fine, creates a unified scale showing "membership"
> # This does not work:
> booboo.gg <- foo.gg + geom_point ( data = bar, colour = "black" ) # so far, so good, but...
> booboo.gg # it will not let me over-ride the colour specifications when it actually tries to construct the graph
> The error message is:
> "Error in `[.data.frame`(df, , var) : undefined columns selected"
> System Information:
> R version 2.7.2 (2008-08-25)
> My goal is to be able to add the additional layer and control its appearance separately from the appearance of
> the first layer. Possible?
This is a bug that caused by an interaction with a bug fix in R 2.7.2.
Its fixed in the development version, and I'm working hard to get a
new release out as soon as possible.
More information about the R-help