0

I have a very basic question. I have created a basic x,y-plot and for my x values which span from -1000 to 0 I would like to stretch last 50 units on x-axis so that from -1000 to -50 values are by default one unit apart but from -50 to 0 they should be 10 units apart. is this possible ??? and how would someone like me do this??

thank you

m

UPDATE: oh, sorry i thought .... well never mind, thnx for the tip:

example

x <- c(-1000:-1)
y <- c(1:1000)
plot(x,y)

Now the plot is simple linear but i would like to have last 50 x-ticks 10 units apart?? does this make sense??

user8060
  • 53
  • 1
  • 2
  • 8
  • Please read [how to make a great r reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) (I didn't downvote, but help us help you). – C8H10N4O2 Dec 15 '15 at 21:11

2 Answers2

2

How about just an x axis transformation:

x <- c(-1000:-1)
y <- c(1:1000)
plot(x,y, type='l')

stretch <- function(x){
  y <- x
  y[x >= -50] <- 10*x[x >= -50]
  y[x < -50] <- x[x < -50] - 500
  y
}

plot(stretch(x), y, type='l', axes=FALSE, frame.plot=TRUE, xlab="", ylab="")

Alternatively, you can use lattice, for starters:

df <- data.frame(x,y)
df$panel <- as.integer(df$x > -50)
library(lattice)
with(df, xyplot(y~x|panel, scales=list(x=list(relation="free"))))

but there is a lot of tweaking needed to get rid of the break between charts there.

C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134
1

One way is to transform x and re-label the x-axis:

xt <- x
xt[x < -50] <- x[x < -50] - 450
xt[x >= -50] <- 10*x[x >= -50]

plot(xt,y,xaxt="n")
axis(1,at=c(200*(-(5:1))-450,-500,-250,0),
     labels = c(-1000,-800,-600,-400,-200,-50,-25,0))

enter image description here

Sam Dickson
  • 5,082
  • 1
  • 27
  • 45