[R] How to add a new plot in the same graph using add=T at the command plot?

Petr PIKAL petr.pikal at precheza.cz
Mon Jun 21 08:52:29 CEST 2010


Hi

In your case it would be wiser to do everything in one step.

plot(c(1.5,2.5), c(media_cob_veloc1.5, media_cob_veloc2.5), ...)

then add your arrows calls

With par(new = T) you will get completely new plot which superpose your 
old one.  It is like if you take two pictures on the same frame of 
photographic film.

Regards
Petr
 

Larissa Lucena <larissalucena at gmail.com> napsal dne 20.06.2010 02:06:07:

> Hi,
> 
> I had just left the plotting graphs work, due to other works that had to 
come 
> first. I tried what was suggested, and all the graphs was places in just 
a 
> image, but each graph overrides the other, even though the x values are 
> different. The scale also was gone. 
> 
> Any clue?
> 
> Thanks again your help!
> 
> My code is like this
> 
> > jpeg()
> > plot(1.5,media_cob_veloc1.5,main="Cenário 600m x 600m - Tempo de Rede 
> Coberta", xlab="Velocidade dos Robôs (em m/s)",ylab="Tempo de Rede 
Coberta 
> (%)", axes=FALSE)
> > axis(1,at=seq(0,4.5,by=0.5),pos=0)
> > axis(2,at=seq(0,100,by=1.0),pos=0)
> > arrows(1.5, media_cob_veloc1.5, 1.5, ic_esq_cob_veloc1.5, length=0.1, 
> angle=90, code=3)
> > arrows(1.5, media_cob_veloc1.5, 1.5, ic_dir_cob_veloc1.5, length=0.1, 
> angle=90, code=3)
> > par(new=T)
> > plot(2.5,media_cob_veloc2.5,main="Cenário 600m x 600m - Tempo de Rede 
> Coberta", xlab="Velocidade dos Robôs (em m/s)",ylab="Tempo de Rede 
Coberta 
> (%)", axes=FALSE)
> > axis(1,at=seq(0,4.5,by=0.5),pos=0)
> > axis(2,at=seq(0,100,by=1.0),pos=0)
> > arrows(2.5, media_cob_veloc2.5, 2.5, ic_esq_cob_veloc2.5, length=0.1, 
> angle=90, code=3)
> > arrows(2.5, media_cob_veloc2.5, 2.5, ic_dir_cob_veloc2.5, length=0.1, 
> angle=90, code=3)
> > par(new=T)
> > plot(4.0,media_cob_veloc4.0,main="Cenário 600m x 600m - Tempo de Rede 
> Coberta", xlab="Velocidade dos Robôs (em m/s)",ylab="Tempo de Rede 
Coberta 
> (%)", axes=FALSE)
> > axis(1,at=seq(0,4.5,by=0.5),pos=0)
> > axis(2,at=seq(0,100,by=1.0),pos=0)
> > arrows(4.0, media_cob_veloc4.0, 4.0, ic_esq_cob_veloc4.0, length=0.1, 
> angle=90, code=3)
> > arrows(4.0, media_cob_veloc4.0, 4.0, ic_dir_cob_veloc4.0, length=0.1, 
> angle=90, code=3)
> > dev.off()
> 
> And the result is like this
> 
> [obrázek odebrán] 

> 2010/6/9 Petr PIKAL <petr.pikal at precheza.cz>
> Hi
> 
> where did you find parameter add=T.
> 
> You can use
> 
> par(new=T)
> before using new plot command
> 
> or use
> 
> points, lines
> 
> Regards
> Petr
> 
> r-help-bounces at r-project.org napsal dne 09.06.2010 16:42:25:
> 
> > I forgot to show my code... it is like this
> >
> >  jpeg()
> > > plot(x,y,main="str", xlab="str",ylab="str", axes=FALSE)
> > > axis(1,at=seq(0,4.5,by=0.5),pos=0)
> > > axis(2,at=seq(0,100,by=1.0),pos=0)
> > > arrows(x, y, x, ic_esq, length=0.1, angle=90, code=3)
> > > arrows(x, y, x, ic_dir, length=0.1, angle=90, code=3)
> > > plot(x1,y1, add=T)
> > Warning messages:
> > 1: In plot.window(...) : "add" năo é um parâmetro gráfico
> > 2: In plot.xy(xy, type, ...) : "add" năo é um parâmetro gráfico
> > 3: In axis(side = side, at = at, labels = labels, ...) :
> >   "add" năo é um parâmetro gráfico
> > 4: In axis(side = side, at = at, labels = labels, ...) :
> >   "add" năo é um parâmetro gráfico
> > 5: In box(...) : "add" năo é um parâmetro gráfico
> > 6: In title(...) : "add" năo é um parâmetro gráfico
> >
> > Thanks
> >
> >
> > On Wed, Jun 9, 2010 at 11:29, Larissa Lucena
> <larissalucena at gmail.com>wrote:
> >
> > > Hi, there!
> > >
> > > I'm having kind this same problem
> > >
> > > https://stat.ethz.ch/pipermail/r-help/2008-October/178221.html
> > >
> > > but I want to display another plot of my data, which is a point with
> two
> > > arrows indicating confidence interval, in the same graph that I've
> just
> > > plotted another, but the "add=T" is not functioning, I'm getting the
> same
> > > error
> > >
> > > Warning messages:
> > > 1: In plot.window(...) : "add" năo é um parâmetro gráfico
> > > 2: In plot.xy(xy, type, ...) : "add" năo é um parâmetro gráfico
> > > 3: In axis(side = side, at = at, labels = labels, ...) :
> > >   "add" năo é um parâmetro gráfico
> > > 4: In axis(side = side, at = at, labels = labels, ...) :
> > >   "add" năo é um parâmetro gráfico
> > > 5: In box(...) : "add" năo é um parâmetro gráfico
> > > 6: In title(...) : "add" năo é um parâmetro gráfico
> > >
> > > In all tutorials I search, I see that the form of doing that is 
using
> the
> > > add=T... Is there another way?
> > >
> > > Thanks in advance!
> > >
> > > --
> > > Larissa
> > >
> >
> >
> >
> > --
> > Larissa
> >
> >    [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.

> 
> 
> 
> -- 
> Larissa



More information about the R-help mailing list