[R] how to create analog stripchart plots of x vs t (t=mm/dd/yyyy hh:mm:ss)

Don MacQueen macq at llnl.gov
Mon Mar 13 17:07:00 CET 2006


Richard,

Since you mentioned that you can reformat the data any way you want, 
I'll add a suggestion.

If you format your date/time data using R's default format, then your 
R script can be a little simpler.

   "2006-03-11 15:09",0.014652

(i.e., put the date and time together in one column, using the same 
standards-based format that R uses)


Adapting Jim's solution:

>  x <- read.csv('clipboard', as.is=T, 
>header=F,col.names=c('TimeStamp','TheValue'))
>  x
               TimeStamp    TheValue
1 2006-03-11 15:09 0.014652
2 2006-03-11 15:08 0.014652
3 2006-03-11 15:06 0.000000

>  x$TimeStamp <- as.POSIXct(x$TimeStamp)

>  x$TimeStamp  # make sure the dates look correct
[1] "2006-03-11 15:09:00" "2006-03-11 15:08:00" "2006-03-11 15:06:00"

>  plot(x$TimeStamp,x$TheValue)
>  with(x,plot(TimeStamp,TheValue))

You get the added benefit that you can sort the lines in the text 
file and it will sort
in time order.

-Don

At 5:06 PM -0500 3/11/06, jim holtman wrote:
>I think that you problem is that your format statement should be "%m/%d/%Y
>%H:%M";  notice the capital 'y' for a 4 digit year.  You were probably
>getting NAs for dates.
>
>Here is what I got after reading in your partial data:
>
>>  x <- read.csv('clipboard', as.is=T, header=F)
>>  x
>          V1    V2       V3
>1 3/11/2006 15:09 0.014652
>2 3/11/2006 15:08 0.014652
>3 3/11/2006 15:06 0.000000
>>  x.date <- strptime(paste(x$V1, x$V2), format="%m/%d/%Y %H:%M")
>>  x.date  # make sure the dates look correct
>[1] "2006-03-11 15:09:00" "2006-03-11 15:08:00" "2006-03-11 15:06:00"
>>  plot(x.date, x$V3)
>>
>
>
>
>On 3/11/06, Richard Evans <revans at jlab.org> wrote:
>>
>>  Hello r-experts,
>>  I sure could us a little help.
>>
>>  I have an ever updating text file with timestamped data in it. I can
>>  reformat in anyway I want if need be but currently I have chosen to make
>>  columns of date, time and measuresed value (comma delimeted and with the
>>  dates and times in quotes to interpret them as strings).
>>
>>  Here is a small section of my text data file:
>>
>>  "3/11/2006","15:09",0.014652
>>  "3/11/2006","15:08",0.014652
>>  "3/11/2006","15:06",0.000000
>>  ...etc...
>>
>>  I am trying to make a plot of 'X' vs. 't'
>>  where 'x' is a simple numerical vector of N elemets
>>  and 't'   is a timestamp like "mm/dd/yyyy hh:mm:ss"
>>  (also of N elements)
>>
>>  here is how i am getting the data:
>>  >
>>  >TheData <- scan("MyDataFile.txt",sep=",",list("","",0))
>>  >TheDates <- TheData[[1]]
>>  >TheTimes <- TheData[[2]]
>>  >TheValue <- TheData[[3]]
>>  >
>>  and here is how i am making the datetime objects:
>>  >
>>  >TimeStampStr <- paste(TheDates,TheTimes)
>>  >TimeStampObj <- strptime(xStamp,"%m/%d/%y %H:%M:%S")
>>  >
>>  and then i try to plot it with:
>>  >
>>  >plot(TimeStampObj,TheValues)
>>  >
>>  but this is where i get an error like this:
>>  >
>>  Read 54 records
>>  Error in plot.window(xlim, ylim, log, asp, ...) :
>>         need finite 'ylim' values
>>  In addition: Warning messages:
>>  1: no finite arguments to min; returning Inf
>>  2: no finite arguments to max; returning -Inf
>>
>>  Can someone help me understand what i need to do?
>>  Am I going about this the wrong way?
>>  Is there a smarter/more elegant way to do this?
>>
>>  And advice is greatly apreciated.
>>
>>  Sincerest thanks (in advance),
>>  - revansx
>>
>>  P.S.
>>  here is an small section of my input file:
>>
>>  ______________________________________________
>>  R-help at stat.math.ethz.ch mailing list
>>  https://stat.ethz.ch/mailman/listinfo/r-help
>>  PLEASE do read the posting guide!
>>  http://www.R-project.org/posting-guide.html
>>
>
>
>
>--
>Jim Holtman
>Cincinnati, OH
>+1 513 646 9390 (Cell)
>+1 513 247 0281 (Home)
>
>What the problem you are trying to solve?
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA




More information about the R-help mailing list