[R] How to add two different axis to one plot?

Austin, Matt maustin at amgen.com
Mon Jan 30 05:59:58 CET 2006


Using traditional graphics you probably want to look at

?lines, ?points, ?text . . . 

These allow you to add to your plot without calling new axes.

For custom axes:

plot(1:10, 1:10, axes=FALSE)
lines(1:10, 10:1)
points(1:10, runif(10, 2, 5), col=1, pch=21, bg=3, cex=3)
axis(1, at=1:10)
axis(3, at=1:10, lab=10:1)
axis(2)
box()

Look  at ?axis for details.

--Matt


-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Michael
Sent: Sunday, January 29, 2006 8:49 PM
To: A.Robinson at ms.unimelb.edu.au
Cc: R-help at stat.math.ethz.ch
Subject: Re: [R] How to add two different axis to one plot?


No this is not good.

When I used par(new=TRUE), it does not adjust axis accordingly...

Thus two different axes end up overlap together.

For example, if my first plot has x-axis from 0 to 10, with ticks at 1, 3,
5, 7, 9;

and my second plot has x-axis from 2 to 12, with ticks at 2, 2.9, 5.5...

then the two plots have two different axes with ticks overlap together.

The visual appearance is very bad.

On 1/29/06, Andrew Robinson <A.Robinson at ms.unimelb.edu.au> wrote:
>
> Use the axis() command to add custom axes.
>
> To "hold" the plot, insert
>
> par(new=TRUE)
>
> between the plot statements, thus:
>
> plot(x1, y1, etc ...)
> par(new=TRUE)
> plot(x2, y2, etc ...)
>
>
>
> Andrew
>
> On Mon, January 30, 2006 2:49 pm, Michael said:
> > Hi all,
> >
> > I need to put two different axis to one plot. On the top of the plot, I
> > need
> > to put one axis, with increments from left side to the right side; then
> at
> > the bottom of the same plot, I need to put another axis, with increments
> > from right side to the left side and showing a different unit. How do I
> do
> > that?
> >
> > By the way, is there a "hold" command for plotting?
> >
> > If I first plot a picture, how to add another "plot" command onto it
> > without
> > erasing it?
> >
> > In matlab, it can be convinient done by "hold on" and "hold off"... and
> > can
> > I do it in R?
> >
> > Thanks a lot,
> >
> > Micheal
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> >
>
>
> Andrew Robinson
> Senior Lecturer in Statistics                       Tel: +61-3-8344-9763
> Department of Mathematics and Statistics            Fax: +61-3-8344 4599
> University of Melbourne, VIC 3010 Australia
> Email: a.robinson at ms.unimelb.edu.au    Website:
> http://www.ms.unimelb.edu.au
>
>

	[[alternative HTML version deleted]]

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




More information about the R-help mailing list