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

Gabor Grothendieck ggrothendieck at gmail.com
Mon Jan 30 06:13:34 CET 2006

```See this thread:

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/57707.html

On 1/29/06, Michael <comtech.usa at gmail.com> wrote:
> 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
>

```