0

Currently I am doing some cumulative distribution plot using R and I tried to set x-axis with decreasing power values (such as 10000,1000,100,10,1) in equal sizes but I failed:

n<-ceiling(max(test))
qplot(1:n, ecdf(test)(1:n), geom="point",xlab="check-ins", 
      ylab="Pr(X>=x)")+ geom_step()
      +scale_x_reverse(breaks=c(10000,1000,100,10,1))    
      +scale_shape_manual(values=c(15,19))

It seems that the output has large interval for 10000, then all the other 4 values are left in the small right size of x-axis together. Does anyone knows how to set x-axis value with different intervals in equal sizes? Many Thx.

Frown
  • 259
  • 1
  • 12
  • 1
    Have you checked this? http://stackoverflow.com/questions/11053899/how-to-get-a-reversed-log10-scale-in-ggplot2 – mts Jun 22 '15 at 20:49
  • Second question today with this theme. Is this for a course? – IRTFM Jun 23 '15 at 06:20
  • @mts Thx, I have checked this, but my situation is a little bit different from that one, suppose that I have reversed the x-axis value, but I can't set the intervals (1000,100,10,1) of x-axis to be equal size... – Frown Jun 23 '15 at 08:48
  • @BondedDust it is really nice and helpful to present this kind of course, plz... – Frown Jun 23 '15 at 08:52
  • @hui I don't see how your situation is different and in my humble opinion this is a duplicate. Nevertheless I copy&pasted some code that should satisfy your needs (see answer below), if not please clarify exactly what you mean with "intervals in equal sizes". – mts Jun 23 '15 at 09:02
  • @mts sorry, now I got it :) – Frown Jun 23 '15 at 09:08

2 Answers2

1

Using this code:

set.seed(12345)
test=rnorm(20,1000,5000)
n<-ceiling(max(test))
qplot(1:n, ecdf(test)(1:n), geom="point",xlab="check-ins", 
      ylab="Pr(X>=x)")+ geom_step()+  scale_x_log10()+ scale_x_reverse(breaks=c(10000,5000,1000,1))

I got this:

enter image description here

Is that what you want?

Robert
  • 5,038
  • 1
  • 25
  • 43
  • Many thx, but if I set the breaks to (10000,1000,100,10,1) the intervals on X-axis are not equal sizes, is there any way to make each interval equal size? – Frown Jun 23 '15 at 08:40
1

Combining the example by @Robert and code from the answer featured here: How to get a reversed, log10 scale in ggplot2?

library("scales")
library(ggplot2)
reverselog_trans <- function(base = exp(1)) {
  trans <- function(x) -log(x, base)
  inv <- function(x) base^(-x)
  trans_new(paste0("reverselog-", format(base)), trans, inv, 
            log_breaks(base = base), 
            domain = c(1e-100, Inf))
}

set.seed(12345)
test=rnorm(20,1000,5000)
n<-ceiling(max(test))
qplot(1:n, ecdf(test)(1:n), geom="point",xlab="check-ins", 
      ylab="Pr(X>=x)")+ geom_step()+  
scale_x_continuous(trans=reverselog_trans(10), breaks = c(10000,1000,100,10,1))

This should do what you want, i.e. the distance on the x-axis from 10000 to 1000 is the same as the one from 10 to 1.

Community
  • 1
  • 1
mts
  • 2,160
  • 2
  • 24
  • 34