coord_equal fails with log scales?

10 views
Skip to first unread message

Stavros Macrakis

unread,
May 21, 2009, 1:01:27 PM5/21/09
to ggplot2
myplot <-
  ggplot(data=data.frame(a=2^(1:10),b=3^(1:10))) +
   geom_line(aes(x=a,y=b)) +
   scale_x_log10() + scale_y_log10()

myplot  #> good plot

myplot + coord_equal()  #> no plot + error
Error in if (length(range) == 1 || diff(range) == 0) { :
  missing value where TRUE/FALSE needed
In addition: Warning message:
In log(c(-0.706085234710432, 4.01741518701423), 10) : NaNs produced

There is a workaround: aes(x=log10(a),...) and custom axis labels etc.

Obviously coord_equal would be problematic if the x and y scale mappings were not the same, but that isn't the case here.

            -s

hadley wickham

unread,
Jun 4, 2009, 5:40:57 PM6/4/09
to macr...@alum.mit.edu, ggplot2
On Thu, May 21, 2009 at 12:01 PM, Stavros Macrakis <macr...@gmail.com> wrote:
> myplot <-
>   ggplot(data=data.frame(a=2^(1:10),b=3^(1:10))) +
>    geom_line(aes(x=a,y=b)) +
>    scale_x_log10() + scale_y_log10()
>
> myplot  #> good plot
>
> myplot + coord_equal()  #> no plot + error
> Error in if (length(range) == 1 || diff(range) == 0) { :
>   missing value where TRUE/FALSE needed
> In addition: Warning message:
> In log(c(-0.706085234710432, 4.01741518701423), 10) : NaNs produced

Hmmm, this is tricky because to make the scales equal, I'm currently
extending the shorter scale to the length of the longer - for this
example it pushes the limits in to the negatives, which is problematic
for log axes. Thanks for the reproducible example - I'll look at it
when I'm re-looking at coord_equal.

Hadley

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

Reply all
Reply to author
Forward
0 new messages