[R] Plot.ts
Gavin Simpson
gavin.simpson at ucl.ac.uk
Tue Jul 9 18:45:36 CEST 2002
Dear List
Thanks to Achim for his suggestion about renaming my columns to get
better labels in the plot and for explaining a bit about how plot.ts
works. I don't have time at the minute (writing up the final bits of my
PhD thesis before I leave for 8 weeks of fieldwork!) to play about with
the internals of plot.ts, but this is something I will have a look at
when I get back.
I realised that perhaps I didn't need the data in a timeseries (ts)
object (I don't need to analyse the data but I do need plots for
comparison to go in my thesis) so I converted the Date column in my data
frame into an object of class POSIXlt using the strptime function, and
then plotted the data like so:
temp.data <- read.csv("Z:/Data/PhD/temp/AWMNtemps.csv")
temp.data$Date <- strptime(as.character(temp.data$Date),
format="%d/%m/%Y %H:%M")
attach(temp.data)
oldpar <- par(mfrow=c(2,1), cex.axis=0.75, mar=c(0, 4, 0, 2), oma=c(3,
1, 3, 1,) + 0.1)
plot(x=Date, y=LAG, axes=FALSE, type="l", ylab="", xaxt="n")
axis(side=2)
box()
plot(x=Date, y=ARR, type="l", ylab="")
mtext(text="Temperature (C)", side=2, outer=TRUE, line=-1)
par(oldpar)
By changing the settings in par() and doing a bit of the axis plotting
myself I was able to get a plot that looked very similar to the output
from plot.ts but one which I could control a little more.
And, whilst I'm here, I'd like to thank all the people on the list who
have responded to my questions over the past year or so since I started
using R, and the same goes for everyone else who has contributed advice
through R-help. I have learned an awful lot about R from the daily
postings to R-help - your time and effort in answering the multitude of
questions is very much appreciated!
All the best,
Gavin Simpson
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson [T] +44 (0)20 7679 5402
ENSIS Research Fellow [F] +44 (0)20 7679 7565
ENSIS Ltd. & ECRC [E] gavin.simpson at ucl.ac.uk
UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way [W] http://www.ucl.ac.uk/~ucfagls/
London. WC1H 0AP.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
-----Original Message-----
From: owner-r-help at stat.math.ethz.ch
[mailto:owner-r-help at stat.math.ethz.ch] On Behalf Of Achim Zeileis
Sent: 08 July 2002 12:46
To: gavin.simpson
Cc: r-help
Subject: Re: [R] Plot.ts
Gavin Simpson wrote:
>
> Dear list,
>
> I have a time series of 2-hourly temperature data from loggers placed
in
> two lakes. I have created an object of class ts and mts (temp.ts)
using
> the ts() function and have managed to set the start position and the
> frequency to 2-hours.
>
> I now what to produce a plot of these two time series, and the default
> provided by plot.ts() gives a nice plot of the data for the two lakes
in
> two separate panels using the option plot.type="multiple" in
plot.ts().
> I would like to alter the plot a little:
>
> 1) Change the x and y-axis labels, but when I set ylab="" in my call
to
> plot.ts() I get the following message:
>
> >plot.ts(temp.ts, ylab="")
> Error in plot.ts(x[, i], axes = FALSE, xlab = "", ylab = "", log =
log,
> :
> formal argument "ylab" matched by multiple actual arguments
>
> 2) I get the same when I try to not plot the axes:
>
> >plot(temp.ts, cex=0.75, axes=FALSE)
> Error in plot.ts(x[, i], axes = FALSE, xlab = "", ylab = "", log =
log,
> :
> formal argument "axes" matched by multiple actual arguments
>
> 3) I want to change the default labels for the tick marks that the
plot
> has ("2000", "2000.5", "2001", "2001.5") to just show the change of
> year, i.e. indicate where 2001 and 2002 start. But because I do not
see
> how to go about not plotting the axes I am a little stuck.
Yes, that is all a little bit tricky, because plot.mts() essentially
sets the
mfrow parameter to c(2,1) and then sets up 2 different plots. So after
plotting there is also no (nice and simple) way to add something to
these plots with
lines() for example.
Concerning the ylab argument there is a simple (although not elegant)
workaround: plot.mts() takes the colnames() of your mts-object, so you
could change these. But if you want complete control over the axes I
guess the simplest way is to set up the two plots yourself. Look at the
plot.mts() code how it does it.
At least there is no simpler way to do this that I know of...
Z
> Can someone point me in the right direction as to how I can set my own
> y-axis labels for a multiple times series plot, even just setting them
> to "" would be good as I can just use mtext() to add a label for the
> whole plot, and how to specify my own, or control the, labelling of
the
> tick marks on the x-axis?
>
> Many thanks
>
> Gavin Simpson
>
>
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> Gavin Simpson [T] +44 (0)20 7679 5522
> ENSIS Research Fellow [F] +44 (0)20 7679 7565
> ENSIS Ltd. & ECRC [E] gavin.simpson at ucl.ac.uk
> UCL Department of Geography [W]
http://www.ucl.ac.uk/~ucfagls/cv/
> 26 Bedford Way [W] http://www.ucl.ac.uk/~ucfagls/
> London. WC1H 0AP.
>
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-.-
> r-help mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To:
r-help-request at stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-.-
r-help mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list