[R] ggplot2: behaviour with empty datasets
Casper Ti. Vector
caspervector at gmail.com
Fri Dec 23 14:08:26 CET 2011
For example, prepare like this
> df.0 <- data.frame(x = 0, y = 0, note = "1")
> df.1 <- subset(df.0, note == "1")
> df.2 <- subset(df.0, note == "2")
Then a call to
> ggplot() + aes(x = x, y = y) +
> geom_point(data = df.1) + geom_point(data = df.2)
produces the error
> Error in eval(expr, envir, enclos) : object 'x' not found
And a call to
> ggplot(df.1, aes(x = x, y = y, shape = 4)) +
> geom_point() + geom_point(aes(shape = 1), df.2)
plots both a cross (shape = 4) and circle (shape = 1) on position
(0, 0). However, as expected, only a cross should be plotted because
`dt.2' is empty.
So with the current behaviour, if someone writes a script to plot
datasets automatically and distinguish between subsets, he will need
to write different code path for empty and non-empty data subsets.
I think ggplot2 can just choose to "plot nothing" for empty data
subsets, and only produce error when the dataset (union of a subsets) to
plot is completely empty. This can make scripting easier based on
ggplot2.
--
Using GPG/PGP? Please get my current public key (ID: 0xAEF6A134,
valid from 2010 to 2013) from a key server.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111223/5c352bf5/attachment.bin>
More information about the R-help
mailing list