ggplot2 time series with dates on the x-axis

83 views
Skip to first unread message

Keith S Weintraub

unread,
Nov 18, 2015, 8:01:46 AM11/18/15
to ggplot2
Folks,
The following code works fine except for the fact that when my time series ends there seems to be an extraneous line that goes past the data.

Any help would be appreciated.

Thanks,
KW


require(lubridate)
require(ggplot2)
library(scales)

wts<-read.table(header = TRUE, text = "
Num dte Wt
0 3/23/2015 233
1 3/30/2015 231
2 4/6/2015 231
3 4/13/2015 227.05
4 4/20/2015 226.8
5 4/27/2015 224.4
6 5/4/2015 224.8
7 5/11/2015 224.4
8 5/25/2015 222.4
9 5/31/2015 224.4
10 6/8/2015 221.0
11 6/15/2015 220.4
12 6/22/2015 219.8
13 6/29/2015 219.6
14 7/6/2015 219.0
15 7/13/2015 221.4
16 7/20/2015 219.2
17 7/27/2015 218.0
18 8/3/2015 217.6
19 8/10/2015 216.4
20 8/17/2015 215.2
21 8/24/2015 213.8
23 9/8/2015 218.6
24 9/14/2016 215.6
25 9/28/2015 212.8
26 10/5/2015 214.8
27 10/12/2015 212.4
28 10/19/2015 211.4
29 10/26/2015 210.6
30 11/2/2015 210.0
31 11/9/2015 210.4
32 11/16/2015 207.8",
stringsAsFactors = FALSE)

wts$dte<-as.Date(mdy(wts$dte))

p <- ggplot(wts, aes(x=dte, y=Wt)) + geom_line()




---
KW







Roman Luštrik

unread,
Nov 18, 2015, 8:04:58 AM11/18/15
to Keith S Weintraub, ggplot2
Hi,

ggplot draws just fine. You have a datum at datum (hehe) of September 14, 2016.

> sort(wts$dte)
 [1] "2015-03-23" "2015-03-30" "2015-04-06" "2015-04-13" "2015-04-20" "2015-04-27" "2015-05-04" "2015-05-11" "2015-05-25" "2015-05-31"
[11] "2015-06-08" "2015-06-15" "2015-06-22" "2015-06-29" "2015-07-06" "2015-07-13" "2015-07-20" "2015-07-27" "2015-08-03" "2015-08-10"
[21] "2015-08-17" "2015-08-24" "2015-09-08" "2015-09-28" "2015-10-05" "2015-10-12" "2015-10-19" "2015-10-26" "2015-11-02" "2015-11-09"
[31] "2015-11-16" "2016-09-14"

Cheers,
Roman








--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
In God we trust, all others bring data.

Keith S Weintraub

unread,
Nov 18, 2015, 8:46:34 AM11/18/15
to Roman Luštrik, ggplot2
Thanks!

I never even thought to think that I had a data error.

All should have been in 2015!

Thanks again,
KW

ANTONIOSPARS GITONGA

unread,
Nov 18, 2015, 9:20:19 AM11/18/15
to Keith S Weintraub, Roman Luštrik, ggplot2
Hi

I got some big data on weather from ftp://ftp.cpc.ncep.noaa.gov/fews/fewsdata/africa/arc2/bin/
This data is in binary form and each zip file has 601,511 elements.
This is in vector form. I need form a matrix of rows as days and columns as years. This needs to be looped for 601,511 pixels. my approximation is that this will take 10 days.
rm(list=ls(all=TRUE))

library(RCurl)
library(downloader)

#set path here
setwd("C:/Users/david/OneDrive/SFSA/Pricing Engine")

start.date<-as.Date("19830101","%Y%m%d")
stop.date<-Sys.Date()-2
bin.dates<-paste0("daily_clim.bin.",format(seq.Date(start.date,stop.date,1),"%Y%m%d"),".gz")

for (bin.date in bin.dates){
  prebinaddress<-"ftp://ftp.cpc.ncep.noaa.gov/fews/fewsdata/africa/arc2/bin/"
  postbinaddress<-paste0(prebinaddress,bin.date)
  download.file(postbinaddress,bin.date,quiet = FALSE)
  print(postbinaddress)
}

antonio

Ben Bond-Lamberty

unread,
Nov 18, 2015, 11:00:03 AM11/18/15
to Keith S Weintraub, ggplot2
You have a data entry error in row 24 - the "9/14/2016" date should be
"9/14/2015", look like.

Ben

Brandon Hurr

unread,
Nov 18, 2015, 11:23:48 AM11/18/15
to ANTONIOSPARS GITONGA, Keith S Weintraub, Roman Luštrik, ggplot2
Antonio,

It seems as though you've not quite got your data into R. That's a bit
early to be emailing the ggplot2 list. You might try the manipulatr
list or stackoverflow and then come back when you have a plotting
issue.

Thanks,
Brandon

Jason Law

unread,
Nov 18, 2015, 7:49:03 PM11/18/15
to Keith S Weintraub, ggplot2
Entry 24 is 9/14/2016; looks like a data entry error.

J

Reply all
Reply to author
Forward
0 new messages