uneven spacing on axis with R

匿名 (未验证) 提交于 2019-12-03 02:28:01

问题:

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!