简体   繁体   English

如何以log2(n + 1)格式在x轴上重新缩放标签?

[英]How to rescale label on x axis in log2(n+1) format?

I want to format my x-axis in log2(n+1) format so the x-axis labels correspond to 1, 2, 4, 16 and so on. 我想将我的x轴格式化为log2(n+1)格式,因此x轴标签对应于log2(n+1)等。

Input: 输入:

x <- c(1, 2, 3, 11, 15)
y <- c(1.1, 1.2, .4, 2.1, 1.5)

plot(log2(x + 1), y, axes=FALSE)
axis(1, at=(labels=as.character(formatC(x))), cex.axis=0.9)

But plot I get still has the original x-axis values. 但是我得到的图仍然具有原始的x轴值。

在此处输入图片说明

How can I make my x-axis powers of 2 (1, 2, 4, 16, etc.)? 如何使我的x轴幂为2(1、2、4、16等)?

I guess this is what you want. 我想这就是你想要的。

x<-c(1,2,3,11,15) 
y<-c(1.1,1.2,.4,2.1,1.5)
lab<-c(1,2,4,16)
plot(log2(x+1),y,xaxt="n",xlab="x")
axis(1,at=log2(lab+1),labels=lab)

It might also be useful to calculate equally spaced labels: 计算等距标签也可能很有用:

lab<-round(2^seq(min(log2(x+1)),max(log2(x+1)),length.out=4)-1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM