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 轴值?许多谢谢。

4

2 回答 2

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 回答
1

结合@Robert 的示例和此处提供的答案中的代码:如何在 ggplot2 中获得反转的 log10 比例?

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

这应该可以满足您的要求,即 x 轴上从 10000 到 1000 的距离与从 10 到 1 的距离相同。

于 2015-06-23T08:58:01.960 回答