0

I would like to plot a vector y against x in R where the direction of x is reversed. For example, if

x = c(1,2,3,4)
y = c(10,20,30,40)
plot(x,y)

I would like to have a diagonal in the opposite direction, starting with (4,40) and ending in (1,10).

I thought that rev() would do this, i.e.

plot(rev(x), y)

but this reverses x without y, while

plot(rev(x), rev(y))

is equivalent to the original plot(x,y)

I'm sure there's a very simple way to do this (other than the contrived approach of using -x), but I can't seem to find it.

M--
  • 25,431
  • 8
  • 61
  • 93
Max
  • 487
  • 5
  • 19
  • Reverse the `xlim` - `plot(x, y, xlim=rev(range(x)))` - as suggested here - https://stackoverflow.com/questions/37849401/reverse-the-scale-of-the-x-axis-in-a-plot – thelatemail Apr 02 '23 at 21:02

0 Answers0