Re: [R] overlap different line in a xyplot (lattice)

2010-12-13 Thread Francesco Nutini


 From: fe...@nfrac.org
 Date: Sun, 12 Dec 2010 11:47:55 +1100
 Subject: Re: [R] overlap different line in a xyplot (lattice)
 To: ehl...@ucalgary.ca
 CC: nutini.france...@gmail.com; r-help@r-project.org
 
 On 12 December 2010 00:08, Peter Ehlers ehl...@ucalgary.ca wrote:
  On 2010-12-11 03:12, Francesco Nutini wrote:
 
  mmmh, yes this method works...
  but I have to overlap this two graphs:
 
   xyplot(a ~b |sites, data=dataset, col=red)
 
   xyplot(c ~b |sites, data=dataset, col=blue)
 
 
  a, b and c are columns in the same dataset. Sites is also a column in
  the dataset, but it's a factorial variables.
  How can I use your method?
 
  The idea is the same: you need to get your data
  into long format with a grouping variable and
  then use the 'groups' argument to xyplot.
  Here's fake data frame (you should have provided one):
 
   DF - data.frame(y1 = rnorm(30),
   y2 = rnorm(30) + 2,
   x  = rep(1:10, 3),
sites = gl(3, 10, lab=LETTERS[1:3]))
 
  ## Use the reshape2 package to melt the data:
  ## (or use reshape() in base R)
   require(reshape2)
   DF1 - melt(DF, measure.vars = c('y1', 'y2'),
  variable.name = 'grp', value.name = 'y')
 
  ## and plot:
   require(lattice)
   p - xyplot( y ~ x | sites, data = DF1, groups = grp,
  col = c(red, blue), type = b)
   print(p)
 
  Peter Ehlers
 
 
 By the way, in this particular case there is a shortcut which does the
 reshaping internally:
 
 xyplot(y1 + y2 ~ x | sites, DF, type = b)


Great Felix! this is what I was looking for! 
But if y1 and y2 have a different scales? Can I plot, for example y2, on 
secondary axis?

Thanks for your help,

Francesco Nutini


 
  sorry for my ignorance!
 
  Francesco Nutini
 
Date: Fri, 10 Dec 2010 10:13:00 -0800
From: ehl...@ucalgary.ca
To: nutini.france...@gmail.com
CC: r-help@r-project.org
Subject: Re: [R] [r] overlap different line in a xyplot (lattice)
   
On 2010-12-10 07:04, Francesco Nutini wrote:

 dear [R] users,
 is there a way to plot different data (but with the same
  x-variables) in the same xyplot window?
 There are already a similar question, but the answer is not enought
  explanatory...
   
Something like this?
   
x - rep(1:10, 2)
y1 - rnorm(10); y2 - rnorm(10) + 2
y - c(y1, y2)
g - gl(2, 10)
xyplot( y ~ x, groups = g, type = 'b')
   
Peter Ehlers
   


 Thanks a lot,
 Francesco

   
 
  __
  R-help@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.
 
 
 
 
 -- 
 Felix Andrews / $B0BJ!N)(B
 http://www.neurofractal.org/felix/
  
[[alternative HTML version deleted]]

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


Re: [R] overlap different line in a xyplot (lattice)

2010-12-13 Thread Peter Ehlers

On 2010-12-13 03:13, Francesco Nutini wrote:


  From: fe...@nfrac.org


[...snip...]


 
  xyplot(y1 + y2 ~ x | sites, DF, type = b)


Great Felix! this is what I was looking for!
But if y1 and y2 have a different scales? Can I plot, for example y2, on
secondary axis?


There are probably good reasons why you should not
do this, but one way is to use doubleYScale() in the
latticeExtra package.

Peter Ehlers



Thanks for your help,

Francesco Nutini


[...snip...]

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


Re: [R] [r] overlap different line in a xyplot (lattice)

2010-12-11 Thread Francesco Nutini

mmmh, yes this method works...
but I have to overlap this two graphs:



 xyplot(  a ~  b |  sites, data=dataset,  col=red)



 xyplot(  c ~  b |  sites, data=dataset,  col=blue)


a, b and c are columns in the same dataset. Sites is also a column in the 
dataset, but it's a factorial variables.
How can I use your method?
sorry for my ignorance! 

Francesco Nutini

 Date: Fri, 10 Dec 2010 10:13:00 -0800
 From: ehl...@ucalgary.ca
 To: nutini.france...@gmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] [r] overlap different line in a xyplot (lattice)
 
 On 2010-12-10 07:04, Francesco Nutini wrote:
 
  dear [R] users,
  is there a way to plot different data (but with the same x-variables) in 
  the same xyplot window?
  There are already a similar question, but the answer is not enought 
  explanatory...
 
 Something like this?
 
   x - rep(1:10, 2)
   y1 - rnorm(10); y2 - rnorm(10) + 2
   y - c(y1, y2)
   g - gl(2, 10)
   xyplot( y ~ x, groups = g, type = 'b')
 
 Peter Ehlers
 
 
 
  Thanks a lot,
  Francesco
 
 
  
[[alternative HTML version deleted]]

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


Re: [R] overlap different line in a xyplot (lattice)

2010-12-11 Thread Peter Ehlers

On 2010-12-11 03:12, Francesco Nutini wrote:

mmmh, yes this method works...
but I have to overlap this two graphs:


 xyplot(a ~b |sites, data=dataset, col=red)



 xyplot(c ~b |sites, data=dataset, col=blue)



a, b and c are columns in the same dataset. Sites is also a column in
the dataset, but it's a factorial variables.
How can I use your method?


The idea is the same: you need to get your data
into long format with a grouping variable and
then use the 'groups' argument to xyplot.
Here's fake data frame (you should have provided one):

 DF - data.frame(y1 = rnorm(30),
  y2 = rnorm(30) + 2,
  x  = rep(1:10, 3),
   sites = gl(3, 10, lab=LETTERS[1:3]))

## Use the reshape2 package to melt the data:
## (or use reshape() in base R)
 require(reshape2)
 DF1 - melt(DF, measure.vars = c('y1', 'y2'),
 variable.name = 'grp', value.name = 'y')

## and plot:
 require(lattice)
 p - xyplot( y ~ x | sites, data = DF1, groups = grp,
 col = c(red, blue), type = b)
 print(p)

Peter Ehlers


sorry for my ignorance!

Francesco Nutini

  Date: Fri, 10 Dec 2010 10:13:00 -0800
  From: ehl...@ucalgary.ca
  To: nutini.france...@gmail.com
  CC: r-help@r-project.org
  Subject: Re: [R] [r] overlap different line in a xyplot (lattice)
 
  On 2010-12-10 07:04, Francesco Nutini wrote:
  
   dear [R] users,
   is there a way to plot different data (but with the same
x-variables) in the same xyplot window?
   There are already a similar question, but the answer is not enought
explanatory...
 
  Something like this?
 
  x - rep(1:10, 2)
  y1 - rnorm(10); y2 - rnorm(10) + 2
  y - c(y1, y2)
  g - gl(2, 10)
  xyplot( y ~ x, groups = g, type = 'b')
 
  Peter Ehlers
 
  
  
   Thanks a lot,
   Francesco
  
 


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


Re: [R] overlap different line in a xyplot (lattice)

2010-12-11 Thread Felix Andrews
On 12 December 2010 00:08, Peter Ehlers ehl...@ucalgary.ca wrote:
 On 2010-12-11 03:12, Francesco Nutini wrote:

 mmmh, yes this method works...
 but I have to overlap this two graphs:

  xyplot(a ~b |sites, data=dataset, col=red)

  xyplot(c ~b |sites, data=dataset, col=blue)


 a, b and c are columns in the same dataset. Sites is also a column in
 the dataset, but it's a factorial variables.
 How can I use your method?

 The idea is the same: you need to get your data
 into long format with a grouping variable and
 then use the 'groups' argument to xyplot.
 Here's fake data frame (you should have provided one):

  DF - data.frame(y1 = rnorm(30),
                  y2 = rnorm(30) + 2,
                  x  = rep(1:10, 3),
               sites = gl(3, 10, lab=LETTERS[1:3]))

 ## Use the reshape2 package to melt the data:
 ## (or use reshape() in base R)
  require(reshape2)
  DF1 - melt(DF, measure.vars = c('y1', 'y2'),
             variable.name = 'grp', value.name = 'y')

 ## and plot:
  require(lattice)
  p - xyplot( y ~ x | sites, data = DF1, groups = grp,
             col = c(red, blue), type = b)
  print(p)

 Peter Ehlers


By the way, in this particular case there is a shortcut which does the
reshaping internally:

xyplot(y1 + y2 ~ x | sites, DF, type = b)




 sorry for my ignorance!

 Francesco Nutini

   Date: Fri, 10 Dec 2010 10:13:00 -0800
   From: ehl...@ucalgary.ca
   To: nutini.france...@gmail.com
   CC: r-help@r-project.org
   Subject: Re: [R] [r] overlap different line in a xyplot (lattice)
  
   On 2010-12-10 07:04, Francesco Nutini wrote:
   
    dear [R] users,
    is there a way to plot different data (but with the same
 x-variables) in the same xyplot window?
    There are already a similar question, but the answer is not enought
 explanatory...
  
   Something like this?
  
   x - rep(1:10, 2)
   y1 - rnorm(10); y2 - rnorm(10) + 2
   y - c(y1, y2)
   g - gl(2, 10)
   xyplot( y ~ x, groups = g, type = 'b')
  
   Peter Ehlers
  
   
   
    Thanks a lot,
    Francesco
   
  

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




-- 
Felix Andrews / 安福立
http://www.neurofractal.org/felix/

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


Re: [R] overlap different line in a xyplot (lattice)

2010-12-11 Thread Peter Ehlers

On 2010-12-11 16:47, Felix Andrews wrote:

On 12 December 2010 00:08, Peter Ehlersehl...@ucalgary.ca  wrote:


[...snip...]


The idea is the same: you need to get your data
into long format with a grouping variable and
then use the 'groups' argument to xyplot.
Here's fake data frame (you should have provided one):

  DF- data.frame(y1 = rnorm(30),
  y2 = rnorm(30) + 2,
  x  = rep(1:10, 3),
   sites = gl(3, 10, lab=LETTERS[1:3]))

## Use the reshape2 package to melt the data:
## (or use reshape() in base R)
  require(reshape2)
  DF1- melt(DF, measure.vars = c('y1', 'y2'),
 variable.name = 'grp', value.name = 'y')

## and plot:
  require(lattice)
  p- xyplot( y ~ x | sites, data = DF1, groups = grp,
 col = c(red, blue), type = b)
  print(p)

Peter Ehlers



By the way, in this particular case there is a shortcut which does the
reshaping internally:

xyplot(y1 + y2 ~ x | sites, DF, type = b)


Right; thanks for the reminder, Felix. I keep forgetting
about that mainly because I almost always need 'long' data.

Peter Ehlers

[...snip...]

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


[R] [r] overlap different line in a xyplot (lattice)

2010-12-10 Thread Francesco Nutini

dear [R] users,
is there a way to plot different data (but with the same x-variables) in the 
same xyplot window?
There are already a similar question, but the answer is not enought 
explanatory...


Thanks a lot,
Francesco


  
[[alternative HTML version deleted]]

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


Re: [R] [r] overlap different line in a xyplot (lattice)

2010-12-10 Thread Peter Ehlers

On 2010-12-10 07:04, Francesco Nutini wrote:


dear [R] users,
is there a way to plot different data (but with the same x-variables) in the 
same xyplot window?
There are already a similar question, but the answer is not enought 
explanatory...


Something like this?

 x - rep(1:10, 2)
 y1 - rnorm(10); y2 - rnorm(10) + 2
 y - c(y1, y2)
 g - gl(2, 10)
 xyplot( y ~ x, groups = g, type = 'b')

Peter Ehlers




Thanks a lot,
Francesco



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


Re: [R] [r] overlap different line in a xyplot (lattice)

2010-12-10 Thread Ben Bolker
Peter Ehlers ehlers at ucalgary.ca writes:

 
 On 2010-12-10 07:04, Francesco Nutini wrote:
 
  dear [R] users,
  is there a way to plot different data (but with the same x-variables) 
 in the same xyplot window?
  There are already a similar question, but the answer is 
 not enought explanatory...
 
 Something like this?
 

  [snip]


 Also possibly the layer() command in the latticeExtra package.

  If there is an answer that doesn't make sense to you it might
be most efficient to post an edited version of that question/answer,
attempting to clarify which parts of the answer you do and don't
understand ...

  A reproducible example would be nice too.

  Ben Bolker

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