[R] overlaying two graphs / plots /lines

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Tue Feb 7 22:18:41 CET 2023


Hi Bogdan,
Try this:

A<-data.frame(x=c(1,7,9,20),
 y=c(39,91,100,3))
B<-data.frame(x=c(10,21,67,99,200),
 y=c(9,89,1000,90,1001)) # one value omitted to equalize the rows
xrange<-range(c(unlist(A$x),unlist(B$x)))
yrange<-range(c(unlist(A$y),unlist(B$y)))
plot(A,type="l",xlim=xrange,ylim=yrange,col="red")
lines(B,lty=2,col="blue")
legend(150,400,c("A","B"),lty=1:2,col=c("red","blue"))

There are other tricks to deal with the differences in range between A and B.

Jim

On Wed, Feb 8, 2023 at 7:57 AM Bogdan Tanasa <tanasa using gmail.com> wrote:
>
>  Dear all,
>
> Any suggestions on how I could overlay two or more graphs / plots / lines
> that have different sizes and the x axes have different breakpoints.
>
> One dataframe is : A :
>
> on x axis : 1 , 7, 9, 20, etc ... (100 elements)
> on y axis : 39, 91, 100, 3, etc ... (100 elements)
>
>
> The other dataframe is : B :
>
> on x axis : 10, 21, 67, 99, 200 etc .. (200 elements).
> on y axis :  9, 0, 89, 1000, 90, 1001. ... (200 elements).
>
> Thanks a lot,
>
> Bogdan
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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