ccshao
ccshao

Reputation: 519

uneven spacing on axis with R

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:

enter image description here

Upvotes: 2

Views: 5760

Answers (3)

AdamO
AdamO

Reputation: 4930

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

Upvotes: 3

Se&#241;or O
Se&#241;or O

Reputation: 17412

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

Upvotes: 2

nograpes
nograpes

Reputation: 18323

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

enter image description here

Upvotes: 2

Related Questions