Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reverse axis order and use a predefined scale in ggplot?

Tags:

r

ggplot2

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?

like image 828
doorguote Avatar asked Aug 11 '13 15:08

doorguote


1 Answers

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))
like image 193
leo277 Avatar answered Oct 07 '22 17:10

leo277