可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a problem in plotting uneven scale plot on x axis with R
Here is an example:
plot(1:100,1:100)
will give the equal tick space on x axis.
However, I want to show the graph with first half of space showing 1 to 10, and the left half space showing 10 to 100, so the points in the 10 to 100 more dense, and points in 1:10
are easier to see. How to do it with R?
Like this:
回答1:
This is not an easy one-off task to complete. You'll actually need to transform to the scaled data and supply custom tick marked axes. Any reason you haven't considered simply logging the x-axis instead? (supplying the option plot(x, y, log='x')
will do that).
What I think you've described is this:
xnew <- ifelse(x<10, x, x/10) plot(xnew, y, axes=FALSE, xlab='x') axis(1, at=c(0, 10, 20), labels=c(0, 10, 100)) axis(2) box()
回答2:
You could log
the x axis:
x<-1:100 y<-1:100 plot(log(x,base=10),y,axes=F) axis(2) axis(1,at=0:2,labels=10^(0:2))
回答3:
For a logarithmic axis, use:
plot(x,y,log="x") ## specifies which axis to put on log scale
For determining how many "tick marks" to use, check
par()$lab
Default is 5,5,7
. To put more x axis labels, do
par(lab=c(10,5,7))
And for y:
par(lab=c(5,10,7))