hadley/ggplot2 — Issue #258: geom_segment doesn't work properly with log scales
Author: wch
Created: 2011-11-04 05:05:25+00:00
State: open

This might be two bugs.

I was trying to add line segments to a graph with log scales, but instead of putting it at my specified coordinates, it puts them at 10 to the power of the coordinate. For example, if I specify x=1 and xend=3, it draws a line from x=10 to xend=1000.

Here's an example using a dataset from the MASS library:

```
library(MASS)

# Diagonal line
ggplot(Animals, aes(x=body, y=brain)) +
geom_point() +
geom_segment(x=1, xend=3, y=1, yend=3) +
scale_x_log10() + scale_y_log10()
```

It also seems to me that the expected behavior of geom_segment in this case isn't clearly specified: should it be visually straight (useful for annotations), or should it be "numerically straight" and thus visually curved?

Potential bug 2: I tried creating my own minimal data set to illustrate the problem, but I can't even get it to draw the line segment! I tried figuring out what the difference is between this data set and the one above, but I made no progress.

```
set.seed(101)
dat <- data.frame(x=10^rnorm(20,2,1), y=10^rnorm(20,2,1))

# Works
ggplot(dat, aes(x=x, y=y)) +
geom_point() +
scale_x_log10() +
scale_y_log10()

# Doesn't work after adding segment
ggplot(dat, aes(x=x, y=y)) +
geom_point() +
geom_segment(x=1, xend=3, y=1, yend=3) +
scale_x_log10() +
scale_y_log10()

#Error in data.frame(evaled, PANEL = data$PANEL) :
# arguments imply differing number of rows: 0, 20
```