2013-04-25 5 views
7

log10スケールでセグメントに注釈を付けるときに、ggplotでかなり混乱した機能が見つかりました。これは私が後だものですに対しセグメント10のセグメント注釈は、セグメントの終わりと始まりのために異なって動作しますか?

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

::次のコードは、下の図を作成し

つまり
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

、私はlog10のエンドポイントを変換する必要がありますx軸上のセグメントの最初の部分ではありません。この動作には論理的な説明がありますか?私はaes() does the transformationsを理解していますが、この場合、x軸の変換は均一でなければなりません(まあ、log10)、そうですか?

私が働いている:それはannotate()xend値で使用されている場合、これは(だけではなくscale_x_log10()用)scales()のバグであることがわかっ

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

答えて

1

が提供される(それはWによって問題としてalready filledです.Chang)。この場合、xendの変換は一方向のみで行われます。値のlog10は取り込まれませんが、出力が計算されます。例えば、"rect"annotate()xminで使用され、場合問題なく

scale_x_log10()作品は、xmax値が設けられています。この問題の

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

回避策は、data=NULLaes()の内側に入れて他のすべての値とgeom_segment()を使用することです。

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

関連する問題