2013-08-11 7 views
5

私はpast postを読んで、scale_reversescale_log10を同時に使用することを尋ねました。私は "逆"を求める私のスケールが "スケール"パッケージのあらかじめ定義されたスケールであることを除いて、同様の問題があります。ここに私のコードです:ggplotで軸の順序を逆転させ、既定のスケールを使用する方法は?

##Defining y-breaks for probability scale 
    ybreaks <- c(1,2,5,10,20,30,40,50,60,70,80,90,95,98,99)/100 

    #Random numbers, and their corresponding weibull probability valeus (which I'm trying to plot) 
    x <- c(.3637, .1145, .8387, .9521, .330, .375, .139, .662, .824, .899) 
    p <- c(.647, .941, .255, .059, .745, .549, .853, .451, .352, .157) 
    df <- data.frame(x, p) 

    require(scales) 
    require(ggplot2) 

    ggplot(df)+ 
     geom_point(aes(x=x, y=p, size=2))+ 
     stat_smooth(method="lm", se=FALSE, linetype="dashed", aes(x=x, y=p))+ 
     scale_x_continuous(trans='probit', 
          breaks=ybreaks, 
          minor_breaks=qnorm(ybreaks))+ 
     scale_y_log10() 

結果のプロット: 詳細についてはPlot 、私が達成しようとしているスケールは0で、スケールの両端に細かい解像度を(持っている確率プロットのスケールは、あると1)は、中間値(0.5)に向かって絶えず低下する解像度で極端な事象を示す。

scale_x_continuous確率尺度と同時にscale_x_reverseを使用したいと考えていますが、どのようにカスタム尺度でビルドするかわかりません。これに関するガイダンスは?

答えて

0

2つの変換を結合しようとするのではなく、既存のデータを変換してからプロットするのはなぜですか? 次のように正しいと思われます。 scale_(x|y)_reverse()

#http://r.789695.n4.nabble.com/Inverse-Error-Function-td802691.html 
erf.inv <- function(x) qnorm((x + 1)/2)/sqrt(2) 
#http://en.wikipedia.org/wiki/Probit#Computation 
probit <- function(x) sqrt(2)*erf.inv((2*x)-1) 
# probit(0.3637) 
df$z <- probit(df$x) 
ggplot(df)+ 
    geom_point(aes(x=z, y=p), size=2)+ 
    stat_smooth(method="lm", se=FALSE, linetype="dashed", aes(x=z, y=p))+ 
    scale_x_reverse(breaks = ybreaks, 
        minor_breaks=qnorm(ybreaks))+ 
    scale_y_log10() 
0

引数はあなたが単純にやるべきscale_(x|y)_continuous()に渡されます。

scale_x_reverse(trans='probit', breaks = ybreaks, minor_breaks=qnorm(ybreaks)) 
関連する問題