[R] Zoo Data
arun
smartpink111 at yahoo.com
Fri Mar 8 21:11:57 CET 2013
Hi Jakob,
dat1<-read.table(text="
TIME, Value1, Value2
01.08.2011 02:30:00, 4.4, 4.7
01.09.2011 03:00:00, 4.2, 4.3
01.11.2011 01:00:00, 3.5, 4.3
01.12.2011 01:40:00, 3.4, 4.5
01.01.2012 02:00:00, 4.8, 5.3
01.02.2012 02:30:00, 4.9, 5.2
01.08.2012 02:30:00, 4.1, 4.7
01.12.2012 03:00:00, 4.7, 4.3
01.01.2013 01:00:00, 3, 4.3
01.01.2013 01:30:00, 3.8, 4.1
01.01.2013 02:00:00, 3.8, 4.3
01.01.2013 02:30:00, 3.9, 4.2
01.01.2013 03:00:00, 3.7, 4.5
01.01.2013 03:30:00, 3.5, 4.1
01.02.2013 02:00:00, 3.8, 4.3
",sep=",",header=TRUE,stringsAsFactors=FALSE)
dat1$TIME<-as.POSIXct(dat1$TIME,format="%d.%m.%Y %H:%M:%S")
library(zoo)
z1<- zoo(dat1[,-1],dat1[,1])
plot(z1,plot.type="single",col=1:2,xaxt="n")
tt<- time(z1)
axis(side=1,at=tt,labels=FALSE)
ix<- seq(1,length(tt),4) #can change here
fmt<- "%b-%Y"
labs<- format(tt,fmt)
axis(side=1,at=tt[ix],labels=labs[ix],tcl=-0.7,cex.axis=0.7)
legend("topleft",colnames(z1),lty=1,col=1:2)
#subset
z2<- zoo(dat1[1:5,-1],dat1[1:5,1])
Hope this helps.
A.K.
----- Original Message -----
From: "jakob.hahn at gmail.com" <jakob.hahn at gmail.com>
To: smartpink111 at yahoo.com
Cc:
Sent: Friday, March 8, 2013 10:05 AM
Subject: Zoo Data
Hey Arun,
thank you so far, maybe you can tell me 2 more things:
1st-how to deal with the xlim - right now R just makes me 2 dates on x-axis with Dez31 and Feb28 - how to define the interval.
2nd-I am plotting multiple lines with col - is it possible to generate a legend with the name/header of the column from data?
Would be nice, if you could help me!
Thanks
Jakob
More information about the R-help
mailing list