8

I've read a past post asking about using scale_reverse and scale_log10 at the same time. I have a similar issue, except my scale I'm seeking to "reverse" is a pre-defined scale in the "scales" package. Here is my code:

    ##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()

Resulting plot: Plot For more information, the scale I'm trying to achieve is the probability plotting scale, which has finer resolution on either end of the scale (at 0 and 1) to show extreme events, with ever-decreasing resolution toward the median value (0.5).

I want to be able to use scale_x_reverse concurrently with my scale_x_continuous probability scale, but I don't know how to build that in any sort of custom scale. Any guidance on this?

Community
  • 1
  • 1
doorguote
  • 413
  • 1
  • 6
  • 14

2 Answers2

3

Arguments in scale_(x|y)_reverse() are passed to scale_(x|y)_continuous() so you should simply do:

scale_x_reverse(trans='probit', breaks = ybreaks, minor_breaks=qnorm(ybreaks))
leo277
  • 439
  • 2
  • 7
0

Rather than try to combine two transformations, why not transform your existing data and then plot it? The following looks like it should be right.

#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()
r.bot
  • 5,309
  • 1
  • 34
  • 45