[R] How to plot multiple variables on the same graph

Moshe Olshansky m_olshansky at yahoo.com
Fri Oct 26 02:39:38 CEST 2007


Is this what you need?

> plot(mat,a,type="l",col="red",ylim=c(0,1))
> lines(mat,b,col="green")
> lines(mat,c,col="blue")

--- Rafael Barros de Rezende
<rafabarros at cedeplar.ufmg.br> wrote:

> 
>    How to plot multiple variables on the same graph
> 
>    Dear R users,
> 
>    I want to plot the following variables (a, b, c)
> on the same graph. The
>    x-axis must be the variable mat and the graph
> must have the type = "l". How
>    can I do that??
> 
>    > a
>     [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
>    > b
>     [1] 0.90665296 0.82473871 0.75269217 0.68917606
> 0.63304639 0.58332339
>     [7] 0.53916690 0.49985555 0.46476916 0.37987824
> 0.30067069 0.20731536
>    [13] 0.13927000 0.10452521 0.08362549
>    > c
>     [1] 0.08734889 0.15347956 0.20272682 0.23858721
> 0.26387711 0.28086150
>     [7] 0.29135865 0.29682524 0.29842560 0.28839505
> 0.25944938 0.19894618
>    [13] 0.13850436 0.10445517 0.08361908
>    > mat
>     [1]  1  2  3  4  5  6  7  8  9 12 16 24 36 48 60
> 
>    Thanks!!
>    Rafael Barros de Rezende
>    MPhill Economics Candidate - Curriculum Lattes:
>    [1]http://lattes.cnpq.br/9826095609825249
>    Cedeplar - Development and Regional Planning
> Center
>    Face, UFMG ([2]http://www.cedeplar.ufmg.br)
>    --
>    Esta mensagem foi verificada pelo sistema de
> antivírus e
>    acredita-se estar livre de perigo.
> 
> References
> 
>    1. http://lattes.cnpq.br/9826095609825249
>    2. http://www.cedeplar.ufmg.br/
> ______________________________________________
> 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.
>



More information about the R-help mailing list