[R] matching two plots

Romain Francois francoisromain at free.fr
Wed Oct 19 21:46:07 CEST 2005


Le 19.10.2005 19:27, Rui Cardoso a écrit :

>Hi,
>
>I have a problem about graphics. I would like to plot two graphs: a barplot 
>and curve. Here is the code:
>
> > barplot(dpois(0:45,20),xlim=c(0,45),names=0:45)
> > curve(dnorm(x,20,sqrt(20)),from=0,to=45,add=T)
>
>Both graphs are drawn in the same figure, however the scale in both graphs 
>dooes not match. For some reason the second plot is shifted to left. I 
>think there is a problem concerning the axis scale.
>
>Thanks a lot.
>
>Rui
>  
>
Hello,

The problem is barplot. To see that :

R> (barplot(dpois(0:45,20),xlim=c(0,45),names=0:45))
R> axis(3)

Try something like :

R> plot(0:45, dpois(0:45,20), type="h", lwd=4, col="gray")
R> curve(dnorm(x,20,sqrt(20)),from=0,to=45,add=T)

Romain

-- 
visit the R Graph Gallery : http://addictedtor.free.fr/graphiques
~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
~~~~~~      Romain FRANCOIS - http://francoisromain.free.fr      ~~~~~~
~~~~~~~~           Doctorant INRIA Futurs / EDF                ~~~~~~~~
~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~




More information about the R-help mailing list