times series trellis plot

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

times series trellis plot

sluedtke
Dear List,

I am struggling with the trellis graphic. A similar problem was mentioned here:

http://r.789695.n4.nabble.com/R-How-can-you-get-N-replicates-of-a-multi-screen-multivariate-time-series-plot-td811850.html


I do have 2 time series data sets. The 2 time series differ in some orders of magnitude. I managed to plot them into 1 graph, but, since the data is that different, on of the data set appears as a line only, well almost. So I would need to set a second y axis before, that is scaled to the second data set.

I know how to do it with the usual plot.window routine or something similar, but not with the trellis graphic of the "lattice" package.

Thanks in advance!

stefan
Reply | Threaded
Open this post in threaded view
|

Re: times series trellis plot

Gabor Grothendieck
On Fri, Mar 2, 2012 at 5:15 PM, sluedtke <[hidden email]> wrote:

> Dear List,
>
> I am struggling with the trellis graphic. A similar problem was mentioned
> here:
>
> http://r.789695.n4.nabble.com/R-How-can-you-get-N-replicates-of-a-multi-screen-multivariate-time-series-plot-td811850.html
>
>
> I do have 2 time series data sets. The 2 time series differ in some orders
> of magnitude. I managed to plot them into 1 graph, but, since the data is
> that different, on of the data set appears as a line only, well almost. So I
> would need to set a second y axis before, that is scaled to the second data
> set.
>
> I know how to do it with the usual plot.window routine or something similar,
> but not with the trellis graphic of the "lattice" package.

xyplot.zoo in the zoo package is a version of lattice's xyplot
specialized to work with time series.  See the help file and also the
examples in it.

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: times series trellis plot

sluedtke
Thanks, a lot!!

On Fri, 2012-03-02 at 18:00 -0500, Gabor Grothendieck wrote:

> On Fri, Mar 2, 2012 at 5:15 PM, sluedtke <[hidden email]> wrote:
> > Dear List,
> >
> > I am struggling with the trellis graphic. A similar problem was mentioned
> > here:
> >
> > http://r.789695.n4.nabble.com/R-How-can-you-get-N-replicates-of-a-multi-screen-multivariate-time-series-plot-td811850.html
> >
> >
> > I do have 2 time series data sets. The 2 time series differ in some orders
> > of magnitude. I managed to plot them into 1 graph, but, since the data is
> > that different, on of the data set appears as a line only, well almost. So I
> > would need to set a second y axis before, that is scaled to the second data
> > set.
> >
> > I know how to do it with the usual plot.window routine or something similar,
> > but not with the trellis graphic of the "lattice" package.
>
> xyplot.zoo in the zoo package is a version of lattice's xyplot
> specialized to work with time series.  See the help file and also the
> examples in it.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: times series trellis plot

sluedtke
In reply to this post by sluedtke
Dear List,

I managed to solve a part of my problem. Anyway, I still do not
understand how to use the lattice package the right way.

An example:

I do have multiple stations (say, with climatological data) and I want
to plot each station on its on panel.  I managed to do this of course
with one variable.

What I want to do:

1) Add other variables to each panel, that worked as well, but a bit by
chance.

2) Add an panel.xblocks to each panel that show the data gaps of any
variable but not the first.

If any of you could provide a minimal example.


Cheers,

Stefan

On Fri, 2012-03-02 at 14:15 -0800, sluedtke wrote:

> Dear List,
>
> I am struggling with the trellis graphic. A similar problem was mentioned
> here:
>
> http://r.789695.n4.nabble.com/R-How-can-you-get-N-replicates-of-a-multi-screen-multivariate-time-series-plot-td811850.html
>
>
> I do have 2 time series data sets. The 2 time series differ in some orders
> of magnitude. I managed to plot them into 1 graph, but, since the data is
> that different, on of the data set appears as a line only, well almost. So I
> would need to set a second y axis before, that is scaled to the second data
> set.
>
> I know how to do it with the usual plot.window routine or something similar,
> but not with the trellis graphic of the "lattice" package.
>
> Thanks in advance!
>
> stefan
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/times-series-trellis-plot-tp4440032p4440032.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: times series trellis plot

Michael Weylandt
Type at your console:

library(lattice)
example(xyplot.zoo)

I think the second and third do what you were asking. Otherwise,
please describe in more detail what you mean about "add other
variables to each panel" -- how do you want these displayed and what
sort of variables are they?

On Tue, Mar 6, 2012 at 4:20 AM, Stefan Luedtke <[hidden email]> wrote:

> Dear List,
>
> I managed to solve a part of my problem. Anyway, I still do not
> understand how to use the lattice package the right way.
>
> An example:
>
> I do have multiple stations (say, with climatological data) and I want
> to plot each station on its on panel.  I managed to do this of course
> with one variable.
>
> What I want to do:
>
> 1) Add other variables to each panel, that worked as well, but a bit by
> chance.
>
> 2) Add an panel.xblocks to each panel that show the data gaps of any
> variable but not the first.
>
> If any of you could provide a minimal example.
>
>
> Cheers,
>
> Stefan
>
> On Fri, 2012-03-02 at 14:15 -0800, sluedtke wrote:
>
>> Dear List,
>>
>> I am struggling with the trellis graphic. A similar problem was mentioned
>> here:
>>
>> http://r.789695.n4.nabble.com/R-How-can-you-get-N-replicates-of-a-multi-screen-multivariate-time-series-plot-td811850.html
>>
>>
>> I do have 2 time series data sets. The 2 time series differ in some orders
>> of magnitude. I managed to plot them into 1 graph, but, since the data is
>> that different, on of the data set appears as a line only, well almost. So I
>> would need to set a second y axis before, that is scaled to the second data
>> set.
>>
>> I know how to do it with the usual plot.window routine or something similar,
>> but not with the trellis graphic of the "lattice" package.
>>
>> Thanks in advance!
>>
>> stefan
>>
>>
>> --
>> View this message in context: http://r.789695.n4.nabble.com/times-series-trellis-plot-tp4440032p4440032.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> [hidden email] 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.
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: times series trellis plot

Gabor Grothendieck
In reply to this post by sluedtke
On Tue, Mar 6, 2012 at 4:20 AM, Stefan Luedtke <[hidden email]> wrote:

> I managed to solve a part of my problem. Anyway, I still do not
> understand how to use the lattice package the right way.
>
> An example:
>
> I do have multiple stations (say, with climatological data) and I want
> to plot each station on its on panel.  I managed to do this of course
> with one variable.
>
> What I want to do:
>
> 1) Add other variables to each panel, that worked as well, but a bit by
> chance.
>
> 2) Add an panel.xblocks to each panel that show the data gaps of any
> variable but not the first.
>

Please provide some minimal data and code in a reproducible
self-contained way as per last two lines on every r-help message.


--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: times series trellis plot

sluedtke
In reply to this post by Michael Weylandt
I spent some more time to understand the examples .. it helped a bit.

But there is still one issue.

Taking example data (my first on, hope it is not confusing ;-)  ) like:


library(latticeExtra)
library(zoo)


#  example Data

timeVect1=seq(as.Date("1990-01-01"), as.Date("2010-12-31"), by="day")
timeVect2=seq(as.Date("1993-01-01"), as.Date("2010-12-31"), by="day")

df1=data.frame(a=runif(length(timeVect1), max=200),
b=runif(length(timeVect1), max=250))
df2=data.frame(a=runif(length(timeVect2), max=2),
b=runif(length(timeVect2), max=1.5))

ts1=zoo(df1, timeVect1)
ts2=zoo(df2, timeVect2)


# Adding some NA values

ts1$a[sample(1:trunc(length(timeVect1)/2), 2000)]=NA
ts1$b[sample(trunc(length(timeVect1)/2):length(timeVect1), 2000)]=NA

ts2$b[sample(1:trunc(length(timeVect2)/2), 2000)]=NA
ts2$a[sample(trunc(length(timeVect2)/2):length(timeVect2), 2000)]=NA




xyplot(ts1, panel = function(x, y, ...) {
        panel.grid(h = 10, v = 10, col = "grey", lty = 3)
        panel.xblocks(x, is.na(y), ..., col="RED")
panel.xyplot(x, y, ...)
})

So I managed to plot the missing data of ts1 to the corresponding panel,
but, how do I add the missing data from ts2 to the plot that show the
data from ts1 for the columns a and b??

Thanks for your efforts.

Stefan




On Tue, 2012-03-06 at 08:33 -0500, R. Michael Weylandt wrote:

> Type at your console:
>
> library(lattice)
> example(xyplot.zoo)
>
> I think the second and third do what you were asking. Otherwise,
> please describe in more detail what you mean about "add other
> variables to each panel" -- how do you want these displayed and what
> sort of variables are they?
>
> On Tue, Mar 6, 2012 at 4:20 AM, Stefan Luedtke <[hidden email]> wrote:
> > Dear List,
> >
> > I managed to solve a part of my problem. Anyway, I still do not
> > understand how to use the lattice package the right way.
> >
> > An example:
> >
> > I do have multiple stations (say, with climatological data) and I want
> > to plot each station on its on panel.  I managed to do this of course
> > with one variable.
> >
> > What I want to do:
> >
> > 1) Add other variables to each panel, that worked as well, but a bit by
> > chance.
> >
> > 2) Add an panel.xblocks to each panel that show the data gaps of any
> > variable but not the first.
> >
> > If any of you could provide a minimal example.
> >
> >
> > Cheers,
> >
> > Stefan
> >
> > On Fri, 2012-03-02 at 14:15 -0800, sluedtke wrote:
> >
> >> Dear List,
> >>
> >> I am struggling with the trellis graphic. A similar problem was mentioned
> >> here:
> >>
> >> http://r.789695.n4.nabble.com/R-How-can-you-get-N-replicates-of-a-multi-screen-multivariate-time-series-plot-td811850.html
> >>
> >>
> >> I do have 2 time series data sets. The 2 time series differ in some orders
> >> of magnitude. I managed to plot them into 1 graph, but, since the data is
> >> that different, on of the data set appears as a line only, well almost. So I
> >> would need to set a second y axis before, that is scaled to the second data
> >> set.
> >>
> >> I know how to do it with the usual plot.window routine or something similar,
> >> but not with the trellis graphic of the "lattice" package.
> >>
> >> Thanks in advance!
> >>
> >> stefan
> >>
> >>
> >> --
> >> View this message in context: http://r.789695.n4.nabble.com/times-series-trellis-plot-tp4440032p4440032.html
> >> Sent from the R help mailing list archive at Nabble.com.
> >>
> >> ______________________________________________
> >> [hidden email] 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.
> >
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: times series trellis plot

Gabor Grothendieck
On Tue, Mar 6, 2012 at 11:14 AM, Stefan Luedtke <[hidden email]> wrote:

> I spent some more time to understand the examples .. it helped a bit.
>
> But there is still one issue.
>
> Taking example data (my first on, hope it is not confusing ;-)  ) like:
>
>
> library(latticeExtra)
> library(zoo)
>
>
> #  example Data
>
> timeVect1=seq(as.Date("1990-01-01"), as.Date("2010-12-31"), by="day")
> timeVect2=seq(as.Date("1993-01-01"), as.Date("2010-12-31"), by="day")
>
> df1=data.frame(a=runif(length(timeVect1), max=200),
> b=runif(length(timeVect1), max=250))
> df2=data.frame(a=runif(length(timeVect2), max=2),
> b=runif(length(timeVect2), max=1.5))
>
> ts1=zoo(df1, timeVect1)
> ts2=zoo(df2, timeVect2)
>
>
> # Adding some NA values
>
> ts1$a[sample(1:trunc(length(timeVect1)/2), 2000)]=NA
> ts1$b[sample(trunc(length(timeVect1)/2):length(timeVect1), 2000)]=NA
>
> ts2$b[sample(1:trunc(length(timeVect2)/2), 2000)]=NA
> ts2$a[sample(trunc(length(timeVect2)/2):length(timeVect2), 2000)]=NA
>
>
>
>
> xyplot(ts1, panel = function(x, y, ...) {
>        panel.grid(h = 10, v = 10, col = "grey", lty = 3)
>        panel.xblocks(x, is.na(y), ..., col="RED")
> panel.xyplot(x, y, ...)
> })
>
> So I managed to plot the missing data of ts1 to the corresponding panel,
> but, how do I add the missing data from ts2 to the plot that show the
> data from ts1 for the columns a and b??

Assuming you want to add indications of missing data from ts2$a to the
a panel and missing data from ts2$b to the b panel then add this line
to your panel function:

        panel.xblocks(time(ts2), is.na(ts2[, panel.number()]), ..., col="RED")


--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: times series trellis plot

sluedtke
That was exactly the line I was looking for!! Perfect and thanks for your time!

On Tue, 2012-03-06 at 16:23 -0800, Gabor Grothendieck [via R] wrote:
panel.xblocks(time(ts2), is.na(ts2[, panel.number()]), ..., col="RED")