r - Segment annotation on log10 scale works differently for the end and the beginning of the segment? -


i found rather confusing feature in ggplot while trying annotate segments on log10 scale. following code produces plot below:

library(ggplot2) dat <- data.frame(x = x <- 1:1000, y = log(x))  ggplot(dat, aes(x = x, y = y)) + geom_line(size = 2) + scale_x_log10() + annotate("segment", x = 0, xend = log10(100), y = log(100), yend = log(100), linetype = 2) + annotate("segment", x = log10(100), xend = log10(100), y = 0, yend = log(100), linetype = 2) 

enter image description here

whereas after:

ggplot(dat, aes(x = x, y = y)) + geom_line(size = 2) + scale_x_log10() + annotate("segment", x = 0, xend = log10(100), y = log(100), yend = log(100), linetype = 2) + annotate("segment", x = 100, xend = log10(100), y = 0, yend = log(100), linetype = 2) 

enter image description here

in other words, have log10 transform endpoint of segment on x-axis, not beginning. behaviour have logical explanation? understand aes() transformations...but in case, transformations on x-axis should uniform (well, log10), right?

i working on:

r version 3.0.0 (2013-04-03) platform: x86_64-w64-mingw32/x64 (64-bit) ggplot2_0.9.3.1  

found bug of scales() (not scale_x_log10()) when used annotate() , xend value provided (it already filled issue w.chang). in case transformation of xend done in 1 direction - log10 of value not taked power calculated.

scale_x_log10() works without problems if, example, "rect" used in annotate() , xmin, xmax values provided.

ggplot(dat,aes(x,y))+geom_line()+   scale_x_log10()+   annotate("rect",xmin=100,xmax=1000,ymin=log(10),ymax=log(200)) 

enter image description here

workaround problem use geom_segment() data=null , other values put inside aes().

ggplot(dat, aes(x = x, y = y)) +   geom_line(size = 2) + scale_x_log10() +   geom_segment(data=null,aes(x = 100, xend = 100, y = 0, yend = log(100)),                                                               linetype = 2) 

enter image description here


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -