[R] To represent on the same plot the relation (y1, x) and (y2, x)

Arnaud Michel michel.arnaud at cirad.fr
Sun Sep 1 07:18:57 CEST 2013


Thank you Arun
But have you a solution if y1 and y2 have not the same unit (ex : the 
unit of y1 is meter and the unit of y2 is Kg)  and if I want the axe of 
y1 at the left of the plot and the axe of y2 at the rigth of the plot....
Michel

Le 31/08/2013 21:27, arun a écrit :
> Hi,
> May be this helps:
>   x<- 1:10
>   set.seed(28)
>   y1<- rnorm(10)
> set.seed(485)
>   y2<- rnorm(10)
>   plot(x,y1,col="red",type="b",ylab="y1:y2")
> lines(y2,col="blue",type="b")
> legend("topleft", legend = c("y1", "y2"),text.col=c("red","blue"))
>
>
>
> #or
> library(ggplot2)
> dat1<- data.frame(x,y1,y2)
> ggplot(dat1,aes(x))+geom_line(aes(y=y1,colour="y1"))+
>    geom_line(aes(y=y2,colour="y2")) +ylab("y1:y2")
>
> A.K.
>
>
>
>
>
> ----- Original Message -----
> From: Arnaud Michel <michel.arnaud at cirad.fr>
> To: R help <r-help at r-project.org>
> Cc:
> Sent: Saturday, August 31, 2013 1:57 PM
> Subject: [R] To represent on the same plot the relation (y1, x) and (y2, x)
>
> Hello,
> I have 3 vectors x, y1 and y2
> I would like to represent on the same plot the two graph (y1, x) and
> (y2, x).
> Is it possible with ggplot ? other package ?
> Thanks for your help
>

-- 
Michel ARNAUD
Chargé de mission auprès du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31



More information about the R-help mailing list