[R] 3 functions on same plot

Martin Maechler maechler at stat.math.ethz.ch
Fri May 9 09:04:46 CEST 2003

>>>>> "ArnaudD" == Dowkiw, Arnaud <Arnaud.Dowkiw at dpi.qld.gov.au>
>>>>>     on Fri, 9 May 2003 16:30:35 +1000 writes:

    ArnaudD> I'd give the same xlim=c(-a,b) and ylim=(-c,d)
    ArnaudD> parameters to these three functions and then, after
    ArnaudD> each function call
    >> par(new=T)
    ArnaudD> But maybe someone has got a better solution.
Yes. One more high-level approach to this is

  matplot(x, cbind(y1,y2,y3), type = "l",  main = "3 curves ...")
and maybe

See the respective help() pages.
A bit less highlevel with a bit more flexibility is

 plot(x, ..... xlim=.., ylim=.., type = "n")
 lines(x, y1, ........)
 lines(x, y2, ........)
 lines(x, y3, ........)

and legend() again.

Yet another even higher level approach is to work with 
lattice graphics.


    > -----Original Message----- 
    > From: Joachim Brouwers <joachim.brouwers at gmx.net>
    > Subject: [R] 3 functions on same plot

    > Hello,

    > How can i plot 3 functions (prior, likelihood and
    > posterior) on the same plot?

More information about the R-help mailing list