Unusual behavior of plots when values of y are small

26 views
Skip to first unread message

Lester Wollman

unread,
Jan 31, 2011, 8:13:08 PM1/31/11
to ggplot2
The following code gives me a normal looking line plot:

z <- data.frame(x = 1:5, y = 1e-6 * c(1, 1.3, 1.5, -1.2, .8))
ggplot(z, aes(x, y)) + geom_line()

However, if I let y be one order of magnitude smaller,

z <- data.frame(x = 1:5, y = 1e-7 * c(1, 1.3, 1.5, -1.2, .8))
ggplot(z, aes(x, y)) + geom_line()

the plot is a straight line along y. It seems that ggplot assumes
that all numbers below about 1e-6 are effectively the same.

I noticed this only in ggplot2 0.8.9, although I am not sure exactly
when this behavior started. I definitely had normal looking line
plots in earlier versions of ggplot2.

Is this a bug or a feature, and is there a simple way to get normal
looking plots for small values of y without having to multiply all y
values by a constant?

----------------------------

Lester Wollman
Statistician
Symmetricom, Inc.

Hadley Wickham

unread,
Feb 2, 2011, 10:27:29 AM2/2/11
to Lester Wollman, ggplot2
Hi Lester,

Yes, it's a bug, but fortunately it's already fixed in the development
version of ggplot2. The problem arises from my incomplete knowledge
of floating point arithmetic - my previous check for zero range was
too imprecise.

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/

Reply all
Reply to author
Forward
0 new messages