[R] Reverse axis in xyplot()

Roger Koenker roger at ysidro.econ.uiuc.edu
Fri Sep 19 00:11:01 CEST 2003


I had this question a while back in trying to do image plots of sparse
matrices and ended up using this:

	image(x=1:p,y=-(n:1),t(z),axes=FALSE, col=col,xlab=xlab,ylab=ylab)
        axis(1,pretty(1:p))
        axis(2,pretty(-(n:1)),labels=rev(pretty(1:n)))


url:	www.econ.uiuc.edu/~roger/my.html	Roger Koenker
email	rkoenker at uiuc.edu			Department of Economics
vox: 	217-333-4558				University of Illinois
fax:   	217-244-6678				Champaign, IL 61820

On Thu, 18 Sep 2003, Arni Magnusson wrote:

> Creating a plot with reverse Y axis is easy enough with traditional
> graphics:
> > x <- 1:3
> > y <- 1:3
> > plot(y~x, ylim=c(3,1))
>   +-----------+
> 1 | o         |
>   |           |
> 2 |     o     |
>   |           |
> 3 |         o |
>   +-----------+
>     1   2   3
>
> But xyplot doesn't grasp my idea:
> > xyplot(y~x, ylim=c(3,1))
>   +-----------+
> 3 |         o |
>   |           |
> 2 |     o     |
>   |           |
> 1 | o         |
>   +-----------+
>     1   2   3
>
> Does anyone know how the reverse Y axis can be rendered with xyplot(),
> perhaps using a customized panel function? I have tried post-processing
> the trellis object elements, but with no luck. I have also tried the
> xyplot(-y~x) workaround, but I don't know how to display the customized
> labels.
>
> Finally, I'm aware of the y<-ordered(y,rev(y)) workaround, but a solution
> for the continuous case would be preferred.
>
> Thanks in advance,
> Arni
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>




More information about the R-help mailing list