将r曲线与log轴转换为log 2轴

时间:2017-08-14 16:35:11

标签: r

我有以下代码:

x <- readClipboard()
> plot(x)
> myData = x
> myResult = ecdf(myData)

> myResult
Empirical CDF 
Call: ecdf(myData)
 x[1:200] = -0.031027, -0.13797, -0.16993,  ..., 0.016108, 0.60295
> plot(myResult, xlim=c(0,1e1), log="x")

这导致基于日志的轴。但是,x轴是基于log 10的。如何将其转换为log base 2?

我尝试过以下选项: 在:

的基础上
x <- 1:10
y <- 1:10
base <- 2
plot(x,y,axes=FALSE)
axis(1,at=x,labels = base^(x))
axis(2,at=y)

我做了:

 base <- 2
> plot(myResult,y,axes=FALSE)
> plot(myResult,axes=FALSE)
> axis(1,at=x,labels = base^(x))
Error in base^(x) : non-numeric argument to binary operator
> axis(1,at=myResult,labels = base^(myResult))
Error in base^(myResult) : non-numeric argument to binary operator

我也没有成功通过magicaxis来做到这一点:

magaxis(magaxis(unlog='x'), powbase=2)
Error in axis(side = list(family = "sans"), at = c(-0.2, 0, 0.2, 0.4,  : 
  invalid axis number -2147483648
> magaxis((unlog='x'), powbase=2)
Error in axis(side = "x", at = c(-0.2, 0, 0.2, 0.4, 0.6, 0.8, 1, 1.2),  : 
  invalid axis number -2147483648
In addition: Warning message:
In axis(side = "x", at = c(-0.2, 0, 0.2, 0.4, 0.6, 0.8, 1, 1.2),  :
  NAs introduced by coercion
> plot(myResult)
> magaxis((unlog='x'), powbase=2)
Error in axis(side = "x", at = c(-0.2, 0, 0.2, 0.4, 0.6, 0.8, 1, 1.2),  : 
  invalid axis number -2147483648
In addition: Warning message:
In axis(side = "x", at = c(-0.2, 0, 0.2, 0.4, 0.6, 0.8, 1, 1.2),  :
  NAs introduced by coercion

1 个答案:

答案 0 :(得分:0)

使用ggplot2scales软件包更容易。

ggplot(my_data, aes(x = VARX, y = VARY)) + geom_point() + scale_y_continuous(trans = log2_trans())