0

現在、Rを使用していくつかの累積分布プロットを行っており、x軸を減少するべき乗値(10000、1000、100、10、1など)で同じサイズに設定しようとしましたが、失敗しました:

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

出力には 10000 の大きな間隔があるようで、他の 4 つの値はすべて x 軸の小さな右側のサイズにまとめられています。等しいサイズで異なる間隔で x 軸の値を設定する方法を知っている人はいますか? 多くのThx。

4

2 に答える 2

1

@Robert の例と、ここで紹介されている回答のコードを組み合わせる: 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))

これは、あなたが望むことをするはずです。つまり、10000 から 1000 までの x 軸上の距離は、10 から 1 までの距離と同じです。

于 2015-06-23T08:58:01.960 に答える
1

このコードの使用:

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

私はこれを得た:

ここに画像の説明を入力

それはあなたが望むものですか?

于 2015-06-22T23:46:22.000 に答える