[R] plotting date data over couple of months

David Winsemius dwinsemius at comcast.net
Thu Jul 14 06:03:02 CEST 2011


On Jul 13, 2011, at 9:42 PM, vamshi999 wrote:

> i am sorry again..
>
> this is my dataset..
>
>
> 'data.frame':   46376 obs. of  19 variables:
> $ scan.no  : int  24 78 61 64 64 64 65 73 79 82 ...
> $ track.no : int  5 48 105 122 124 121 123 380 1073 1093 ...
> $ blip.no  : int  70 323 514 547 549 553 558 5355 7014 7119 ...
> $ date     : chr  "2011-04-29" "2011-04-29" "2011-04-29"  
> "2011-04-29" ...

You told us this was a date. So I used ... , colClasses=c("character",  
"numeric","numeric", "Date", "character", "numeric") in my read  
statement.

But. It's a character vector.

> $ time     : chr  "18:17:56" "18:20:08" "18:24:58" "18:25:05" ...

And so is time

> $ timestamp: num  1.30e+09 1.30e+09 1.30e+09 1.30e+09 1.30e+09 ...

And I cannot tell what information might be in time stamp.

> $ range    : int  1379 937 555 562 562 555 545 2708 593 2354 ...
> $ x        : int  -997 -487 -1 230 139 -1 223 -2362 163 2017 ...
> $ y        : int  -883 -763 -536 -491 -525 -536 -477 1123 -549  
> 1049 ...
> $ z        : int  357 243 144 145 146 144 141 701 153 609 ...
> $ ns       : int  378 72 72 98 115 72 41 31 44 32 ...
> $ area     : int  16579 2144 1270 1750 2061 1270 710 2668 829 2394 ...
> $ int      : num  0.96 0.82 1 0.999 0.969 1 1 0.816 1 1 ...
> $ max      : num  1 0.984 1 1 1 1 1 0.933 1 1 ...
> $ aspan    : int  69 28 36 40 44 36 40 13 12 8 ...
> $ rspan    : int  8 5 2 4 4 2 2 6 5 4 ...
> $ perim    : int  670 613 125 288 206 125 108 445 221 211 ...
> $ Dir      : num  1 1 1 2 1 1 2 1 2 1 ...
> $ bearing  : num  228 213 180 155 165 ...
>
>
> now previously i have not mentioned these variable because i will be
> removing them eventually....
>
> when i run the above code.. i am getting this error message..
>
> plot(dat$date, dat$height, xaxt="n")
>>  axis(1, at=new_data2$date[c(1,46376)],
> + labels=month.abb[ 1+as.POSIXlt(new_data2$date[c(1,46376)])$mon],
> +  line=2,
> + lwd=0)
>
> Error in axis(1, at = new_data2$date[c(1, 46376)], labels =  
> month.abb[1 +  :
>  no locations are finite
> In addition: Warning message:
> In axis(1, at = new_data2$date[c(1, 46376)], labels = month.abb[1 +  :
>  NAs introduced by coercion


So you need to change a character vector to a date for which the  
function as.Date or strptime are useful

Try this to get dates:

dat$dt.real <- as.Date(dat$date)  # should work with the default format

And then the code should give reasonable results.

Further But; reading down below, you want values per hour... funny  
this is the first I heard of this.

dt.time.real <- strptime (paste( dat$date, dat$time), fformat="%Y-%m- 
%d %H:%M:%S")

Now I see the plot. The plot linked below has one level per date so I  
guess you are intending to just divide daily counts by 24. Jeez. All  
that work on getting times was wasted. It's midnight. I'm going to bed.

The plotting of what are known in these parts as "dynamite plots" is  
supported by functions in plotrix and other packages.
Search in RSiteSearch for plotCI or similar. Also Bolker has a page:  http://emdbolker.wikidot.com/blog:dynamite
And Harrell: http://biostat.mc.vanderbilt.edu/twiki/bin/view/Main/DynamitePlots

>
> axis(1, at=new_data2$date, labels=as.POSIXlt(new_data2$date)$mday)
> Error in axis(1, at = new_data2$date, labels =
> as.POSIXlt(new_data2$date)$mday) :
>  no locations are finite
> In addition: Warning message:
> In axis(1, at = new_data2$date, labels = as.POSIXlt(new_data2$date) 
> $mday) :
>  NAs introduced by coercion
>
> i am looking for an output same as the plot in the image below..
> http://r.789695.n4.nabble.com/file/n3666468/graph.jpg
> y - axis is the mean passage rate ( total no. of birds /hr)
>
> i have read the posting guide as you have suggested.....
>
> thank you ..
>
> --
> View this message in context: http://r.789695.n4.nabble.com/plotting-date-data-over-couple-of-months-tp3666298p3666468.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list