How to reverse the sequence of axis Y ??

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to reverse the sequence of axis Y ??

Cleber N.Borges
 

Hello R-users!

My (simple?) doubt: How to reverse the sequence of axis Y ??

the diagram below illustrate my idea...

(default)
   |
   |
.  |
.  |
.  |
3  |
2  |
1  |
0  +----------------------------
   0 1 2 3 ...



like I want...
 
0  |
1  |
2  |
3  |
.  |
.  |
.  |
   |
   +----------------------------
   0 1 2 3 ...


thanks in advance


klebyn

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How to reverse the sequence of axis Y ??

Kristel Joossens
Hello Klebyn,

It might be that a better solution exists, but here is something that
might help you. (I used that all y's are positive!)

R> maxy=ceiling(max(y))
R> plot(x,maxy-y,axes=FALSE)
R> axis(1)
R> axis(2,0:maxy,seq(maxy,0,-1))

If not all your y's are positive define `miny' and take then
R> axis(2,miny:maxy,seq(maxy,miny,-1))

Best regards and good luck,
Kristel

klebyn wrote:

>  
>
> Hello R-users!
>
> My (simple?) doubt: How to reverse the sequence of axis Y ??
>
> the diagram below illustrate my idea...
>
> (default)
>    |
>    |
> .  |
> .  |
> .  |
> 3  |
> 2  |
> 1  |
> 0  +----------------------------
>    0 1 2 3 ...
>
>
>
> like I want...
>  
> 0  |
> 1  |
> 2  |
> 3  |
> .  |
> .  |
> .  |
>    |
>    +----------------------------
>    0 1 2 3 ...
>
>
> thanks in advance
>
>
> klebyn
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


--
__________________________________________
Kristel Joossens        Ph.D. Student
Research Center ORSTAT  K.U. Leuven
Naamsestraat 69         Tel: +32 16 326929
3000 Leuven, Belgium    Fax: +32 16 326732
E-mail:  [hidden email]
http://www.econ.kuleuven.be/public/ndbae49

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How to reverse the sequence of axis Y ??

Marc Schwartz (via MN)
The key here is to set the 'ylim' argument so that the range of the y
axis is rev()ersed.

So:
 
 # Set 'x'
 x <- 0:10

 # set xlim and ylim
 # set ylim to rev() the range() of 'x'
 plot(x, xlim = c(0, 10), ylim = rev(range(x)))

If you actually want to have the 'x' axis value of 0 in the lower left
hand corner as is shown below, you need to adjust the axis style, which
by default ("r") is expanded by 4% of the range of the x and y values
(or xlim and ylim). So use:

  plot(x, xlim = c(0, 10), ylim = rev(range(x)), yaxs = "i", xaxs = "i")

See ?par for more information on 'xaxs' and 'yaxs' relative to axis
styles.

Note also, that once you have reversed the axis range, you can still set
the axes so that the default tickmarks and labels are not drawn and then
use axis() as per normal for custom labels, etc.

  plot(x, xlim = c(0, 10), ylim = rev(range(x)), yaxs = "i", xaxs = "i",
       axes = FALSE)

  # Draw the x axis
  axis(1, at = 0:10)

  # Draw the y axis
  axis(2, at = seq(0, 10, 2), las = 2)

  # Put a box around the plot
  box()


Note that the y axis labels are properly reversed in synch with the
prior range setting for 'ylim' without further manipulation being
required.

HTH,

Marc Schwartz


On Sat, 2005-12-17 at 18:04 +0100, Kristel Joossens wrote:

> Hello Klebyn,
>
> It might be that a better solution exists, but here is something that
> might help you. (I used that all y's are positive!)
>
> R> maxy=ceiling(max(y))
> R> plot(x,maxy-y,axes=FALSE)
> R> axis(1)
> R> axis(2,0:maxy,seq(maxy,0,-1))
>
> If not all your y's are positive define `miny' and take then
> R> axis(2,miny:maxy,seq(maxy,miny,-1))
>
> Best regards and good luck,
> Kristel
>
> klebyn wrote:
> >  
> >
> > Hello R-users!
> >
> > My (simple?) doubt: How to reverse the sequence of axis Y ??
> >
> > the diagram below illustrate my idea...
> >
> > (default)
> >    |
> >    |
> > .  |
> > .  |
> > .  |
> > 3  |
> > 2  |
> > 1  |
> > 0  +----------------------------
> >    0 1 2 3 ...
> >
> >
> >
> > like I want...
> >  
> > 0  |
> > 1  |
> > 2  |
> > 3  |
> > .  |
> > .  |
> > .  |
> >    |
> >    +----------------------------
> >    0 1 2 3 ...
> >
> >
> > thanks in advance
> >
> >
> > klebyn

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html