Re: [R] overlaying two graphs / plots /lines

2023-02-09 Thread Richard O'Keefe
It's easy enough to do this,
the question is "what does it MEAN?"
If you overlay two graphs, what comparisons will
people naturally make, and what do
you want them to make?
What transformations on the x axis would make
two vertically aligned points about the "same" thing?
What transformations on the y axis would make
a vertical displacement of 1cm equally important
for the two frames?
This *semantic* alignment of the tables is too
important to leave up to some blind algorithm.

On Wed, 8 Feb 2023 at 09:57, Bogdan Tanasa  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@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] overlaying two graphs / plots /lines

2023-02-07 Thread Bogdan Tanasa
Thanks a lot Rui and Jim. Works great !

On Tue, Feb 7, 2023, 1:34 PM Rui Barradas  wrote:

> Às 21:18 de 07/02/2023, Jim Lemon escreveu:
> > 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  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@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.
> >
> > __
> > R-help@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.
> Hello,
>
> Here is a ggplot way.
> I'll use the same data.
>
> On each data.frame, create an id column, saying which df it is.
>
>
> 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
>
> suppressPackageStartupMessages({
>library(dplyr)
>library(ggplot2)
> })
>
> bind_rows(
>A %>% mutate(id = "A"),
>B %>% mutate(id = "B")
> )
> #> xy id
> #> 1   1   39  A
> #> 2   7   91  A
> #> 3   9  100  A
> #> 4  203  A
> #> 5  109  B
> #> 6  21   89  B
> #> 7  67 1000  B
> #> 8  99   90  B
> #> 9 200 1001  B
>
>
> To do this in a pipe doesn't change the original data.
> Then pipe the result to ggplot separating the lines by mapping id to
> color. ggplot will automatically take care of the axis ranges.
>
>
> bind_rows(
>A %>% mutate(id = "A"),
>B %>% mutate(id = "B")
> ) %>%
>ggplot(aes(x, y, colour = id)) +
>geom_line() +
>theme_bw()
>
>
> Hope this helps,
>
> Rui Barradas
>
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] overlaying two graphs / plots /lines

2023-02-07 Thread Rui Barradas

Às 21:18 de 07/02/2023, Jim Lemon escreveu:

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  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@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.


__
R-help@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.

Hello,

Here is a ggplot way.
I'll use the same data.

On each data.frame, create an id column, saying which df it is.


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


suppressPackageStartupMessages({
  library(dplyr)
  library(ggplot2)
})

bind_rows(
  A %>% mutate(id = "A"),
  B %>% mutate(id = "B")
)
#> xy id
#> 1   1   39  A
#> 2   7   91  A
#> 3   9  100  A
#> 4  203  A
#> 5  109  B
#> 6  21   89  B
#> 7  67 1000  B
#> 8  99   90  B
#> 9 200 1001  B


To do this in a pipe doesn't change the original data.
Then pipe the result to ggplot separating the lines by mapping id to 
color. ggplot will automatically take care of the axis ranges.



bind_rows(
  A %>% mutate(id = "A"),
  B %>% mutate(id = "B")
) %>%
  ggplot(aes(x, y, colour = id)) +
  geom_line() +
  theme_bw()


Hope this helps,

Rui Barradas

__
R-help@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.


Re: [R] overlaying two graphs / plots /lines

2023-02-07 Thread Jim Lemon
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  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@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.

__
R-help@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.


[R] overlaying two graphs / plots /lines

2023-02-07 Thread Bogdan Tanasa
 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@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.