[R] Simple time series questions

DKOD koday at processtrends.com
Fri Sep 11 15:07:33 CEST 2009


Try this script. I converted test_date to numeric decimal year

link <- "C:\\R_Home\\Charts & Graphs Blog\\R_Chart_Doc\\text_data.csv"
  testdata<- read.table(link, head = T, sep = ",",na.strings = "na")
  test_date = as.Date(testdata$Date,"%d-%m-%y")

# Convert dates to decimal year   
  my_yr <- as.numeric(format(test_date,format="%Y"))
  my_mo <- as.numeric(format(test_date, format="%m"))
  dec_yr <- my_yr + (my_mo+0.5)/12

  plot(dec_yr, testdata$Model, type="l", log="y", xaxs="i", yaxs="i",
     axes=T, xlim = c(2003, 2008))
  points(dec_yr, testdata$BaseDataA, type = "l", col = "red")
  points(dec_yr, testdata$BaseDataB, type = "l", col = "blue")
  grid( col="grey",lty=1)
  box()

Kelly

http://chartsgraphs.wordpress.com http://chartsgraphs.wordpress.com 


gug wrote:
> 
> Thanks - that works great.
> 
> Do you have any suggestions about the grid() problem - i.e. that the
> vertical gridlines do not line up with the x-axis tickmarks (which are
> years)?
> 
> I can't see on what basis the vertical gridlines are being positioned, but
> it doesn't look good that they are not lined up with anything.
> 
> Thanks,
> 
> Guy
> 
> 
> DKOD wrote:
>> 
>> This script worked for me. Be sure to put in your correct link.
>> 
>>   link <- "C:\\R_Home\\Charts & Graphs Blog\\R_Chart_Doc\\text_data.csv"
>>   testdata<- read.table(link, head = T, sep = ",",na.strings = "na")
>>   test_date = as.Date(testdata$Date,"%d-%m-%y") 
>> 
>>   plot(test_date, testdata$Model, type="l", log="y") 
>>   points(test_date, testdata$BaseDataA, type = "l", col = "red")
>>   points(test_date, testdata$BaseDataB, type = "l", col = "blue")
>> 
>> You add 2nd and 3rd series with points command
>> 
>> Hope this helps.
>> 
>> Kelly
>> 
>>  http://chartsgraphs.wordpress.com http://chartsgraphs.wordpress.com 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Simple-time-series-questions-tp25398419p25400652.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list