Warning when using geom_rect with x=NULL but not if using geom_blank() before

8 views
Skip to first unread message

Trevor L Davis

unread,
Jan 7, 2010, 3:37:25 PM1/7/10
to ggplot2
I have an example where I call ggplot with one dataset, then geom_rect
with another dataset, and finally calling geom_line() with the
original dataset and I get a number of warnings of the "In min(x) : no
non-missing arguments to min; returning Inf" variety.

However if I also use geom_blank before the call to geom_rect the
warnings go away.

Am I doing something "wrong" in the first case that is corrected by
using geom_blank in the second case? I am a little confused as to why
I need to use geom_blank to avoid getting warnings from ggplot2. The
resulting graphs seem indistinguishable to me.

Thanks!

Trevor

My example:

nber.dates <-
structure(list(Start = structure(c(1430, 3683, 4230, 7517, 11413,
13879), class = "Date"), End = structure(c(1915, 3864, 4716,
7759, 11656, NA), class = "Date"), ymin = c(-Inf, -Inf, -Inf,
-Inf, -Inf, -Inf), ymax = c(Inf, Inf, Inf, Inf, Inf, Inf)), .Names = c
("Start",
"End", "ymin", "ymax"), row.names = 28:33, class = "data.frame")

fill = "grey80"
color = NA
size = 0.5
alpha = 0.5

require("ggplot2")

ggp <- ggplot(aes(x=date, y=100*unemploy/pop), data=economics)

# First case
# gives me four warnings of "in min(x) : no non-missing arguments to
min: returning Inf
ggp + geom_rect(aes(xmin = Start, xmax = End, x = NULL, y = NULL,
ymin = ymin, ymax = ymax),
color = color, fill = fill, size = 0.5, alpha = 0.5,
data = nber.dates) + geom_line() + theme_bw()

# Second case
# throwing in a geom_blank() before geom_rect "fixes" the warnings
ggp + geom_blank() +
geom_rect(aes(xmin = Start, xmax = End, x = NULL, y = NULL,
ymin = ymin, ymax = ymax),
color = color, fill = fill, size = 0.5, alpha = 0.5,
data = nber.dates) + geom_line() + theme_bw()

hadley wickham

unread,
Jan 8, 2010, 2:34:25 PM1/8/10
to Trevor L Davis, ggplot2
Hi Trevor,

Looks like a bug. I'll add it to my to do list -
http://github.com/hadley/ggplot2/issues/#issue/64

Hadley

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2
>

--
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages