How to set x-axis with decreasing power values in equal sizes

176 views Asked by At

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.

2

There are 2 answers

0
mts On BEST ANSWER

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.

1
Robert On

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?