I am completely misunderstanding how to handle dates. I want to plot a couple of data series against some dates. Simple example 1 below works fine. Unfortunately I have multiple observations per day (no time breakdowns) and observations across years. (example 2 very simplistic version ) Can anyone suggest a quick fix or point me to something to read? I thought that zoo might do it but I seem to be missing something there too. Any suggestions gratefully recieved. Example 1 consecutive dates same year. ================================================x <- "days 9/26/09 9/27/06 9/28/06 9/29/06 9/29/06 9/29/06 10/1/06 10/1/06 10/2/06 10/3/06" mydata <- read.table(textConnection(x), header=TRUE, as.is=TRUE); mydata mydates <- as.Date(mydata[,1], "%m/%d/%y"); mydates mynums <- rnorm(10) plot(mydates, mynums) ===============================================Example 2 (things go blooy!) non-consecutive dates different years. ================================================x <- "days 9/26/09 9/27/06 9/28/06 9/29/06 9/29/06 9/29/06 10/1/07 # <- year changes 10/1/07 10/2/07 10/3/07" mydata <- read.table(textConnection(x), header=TRUE, as.is=TRUE); mydata mydates <- as.Date(mydata[,1], "%m/%d/%y"); mydates mynums <- rnorm(10) plot(mydates, mynums)
So what is wrong with the plots? I used your example, and it appears to plot the data correctly. What were you expecting? On Nov 12, 2007 1:47 PM, John Kane <jrkrideau at yahoo.ca> wrote:> I am completely misunderstanding how to handle dates. > I want to plot a couple of data series against some > dates. Simple example 1 below works fine. > Unfortunately I have multiple observations per day (no > time breakdowns) and observations across years. > (example 2 very simplistic version ) > > Can anyone suggest a quick fix or point me to > something to read? I thought that zoo might do it but > I seem to be missing something there too. > > Any suggestions gratefully recieved. > > > Example 1 consecutive dates same year. > ================================================> x <- "days > 9/26/09 > 9/27/06 > 9/28/06 > 9/29/06 > 9/29/06 > 9/29/06 > 10/1/06 > 10/1/06 > 10/2/06 > 10/3/06" > > mydata <- read.table(textConnection(x), header=TRUE, > as.is=TRUE); mydata > > mydates <- as.Date(mydata[,1], "%m/%d/%y"); mydates > mynums <- rnorm(10) > plot(mydates, mynums) > ===============================================> Example 2 (things go blooy!) > non-consecutive dates different years. > > ================================================> x <- "days > 9/26/09 > 9/27/06 > 9/28/06 > 9/29/06 > 9/29/06 > 9/29/06 > 10/1/07 # <- year changes > 10/1/07 > 10/2/07 > 10/3/07" > > mydata <- read.table(textConnection(x), header=TRUE, > as.is=TRUE); mydata > > mydates <- as.Date(mydata[,1], "%m/%d/%y"); mydates > mynums <- rnorm(10) > plot(mydates, mynums) > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Now your first data point is 9/26/09; is it supposed to be 9/26/06? On Nov 12, 2007 1:47 PM, John Kane <jrkrideau at yahoo.ca> wrote:> I am completely misunderstanding how to handle dates. > I want to plot a couple of data series against some > dates. Simple example 1 below works fine. > Unfortunately I have multiple observations per day (no > time breakdowns) and observations across years. > (example 2 very simplistic version ) > > Can anyone suggest a quick fix or point me to > something to read? I thought that zoo might do it but > I seem to be missing something there too. > > Any suggestions gratefully recieved. > > > Example 1 consecutive dates same year. > ================================================> x <- "days > 9/26/09 > 9/27/06 > 9/28/06 > 9/29/06 > 9/29/06 > 9/29/06 > 10/1/06 > 10/1/06 > 10/2/06 > 10/3/06" > > mydata <- read.table(textConnection(x), header=TRUE, > as.is=TRUE); mydata > > mydates <- as.Date(mydata[,1], "%m/%d/%y"); mydates > mynums <- rnorm(10) > plot(mydates, mynums) > ===============================================> Example 2 (things go blooy!) > non-consecutive dates different years. > > ================================================> x <- "days > 9/26/09 > 9/27/06 > 9/28/06 > 9/29/06 > 9/29/06 > 9/29/06 > 10/1/07 # <- year changes > 10/1/07 > 10/2/07 > 10/3/07" > > mydata <- read.table(textConnection(x), header=TRUE, > as.is=TRUE); mydata > > mydates <- as.Date(mydata[,1], "%m/%d/%y"); mydates > mynums <- rnorm(10) > plot(mydates, mynums) > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
In your examples the first line of your data refers to the year 2009 and Oct 1st is repeated. Is that really what you meant? I can't tell what your problem is from your description other than the data problems cited but there are lots of examples of plotting with zoo in the following which may help you: vignette("zoo") vignette("zoo-quickref") ?plot.zoo ?xyplot.zoo Note that zoo series must be time series, i.e. they must have unique times. On Nov 12, 2007 1:47 PM, John Kane <jrkrideau at yahoo.ca> wrote:> I am completely misunderstanding how to handle dates. > I want to plot a couple of data series against some > dates. Simple example 1 below works fine. > Unfortunately I have multiple observations per day (no > time breakdowns) and observations across years. > (example 2 very simplistic version ) > > Can anyone suggest a quick fix or point me to > something to read? I thought that zoo might do it but > I seem to be missing something there too. > > Any suggestions gratefully recieved. > > > Example 1 consecutive dates same year. > ================================================> x <- "days > 9/26/09 > 9/27/06 > 9/28/06 > 9/29/06 > 9/29/06 > 9/29/06 > 10/1/06 > 10/1/06 > 10/2/06 > 10/3/06" > > mydata <- read.table(textConnection(x), header=TRUE, > as.is=TRUE); mydata > > mydates <- as.Date(mydata[,1], "%m/%d/%y"); mydates > mynums <- rnorm(10) > plot(mydates, mynums) > ===============================================> Example 2 (things go blooy!) > non-consecutive dates different years. > > ================================================> x <- "days > 9/26/09 > 9/27/06 > 9/28/06 > 9/29/06 > 9/29/06 > 9/29/06 > 10/1/07 # <- year changes > 10/1/07 > 10/2/07 > 10/3/07" > > mydata <- read.table(textConnection(x), header=TRUE, > as.is=TRUE); mydata > > mydates <- as.Date(mydata[,1], "%m/%d/%y"); mydates > mynums <- rnorm(10) > plot(mydates, mynums) > > ______________________________________________ > 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. >
On Nov 13, 2007 10:28 PM, Daniel Malter <daniel at umd.edu> wrote:> Hi, > > I want to illustrate when individuals had an event over time. I am using > dotplot from the lattice library. The plot itself works well, but as I have > many individuals, the labels on the y-axis for these individuals overlap. So > the y-axis is unreadable. Therefore, I want to suppress the labels on the y > axis. I could not get it done. axes=FALSE does not work and I tried other > methods, but it seemed to be the wrong command for dotplot (or lattice). > > To see what I mean you can run the following code: > > library(lattice) > TIME=runif(250,0,200) > vector=array(TIME,dim=c(2500)) > subj=c(1:250) > SUBJECT=sample(bidder,2500,replace=TRUE)I get: Error in sample(bidder, 2500, replace = TRUE) : object "bidder" not found> dotplot(SUBJECT~TIME,xlab="Calendar day",ylab="Events by > individual",col=c("black"),col.line="grey90",pch=43) > > That is, I am looking for the argument in the dotplot() function call that > makes the mess on the y-axis disappear.scales = list(y = list(draw = FALSE)) -Deepayan> Alternatively, I would also use a > different type of plot if it serves the same purpose. In particular it would > be nice if the horizontal lines connect only an individuals events (so that > they are not a grid, but rather a function of the data). > > Thanks much, > Daniel > > ______________________________________________ > 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. >