[R] time plotting problem
John Kane
jrkrideau at yahoo.ca
Wed Nov 14 16:04:38 CET 2007
Excellent, that looks very nice!
I had not realised that plotrix would do that and I
was definately hesitating to try and figure out how to
do it myself.
Any idea why all I was getting was a single date on
the x-axis when just doing plot?
--- Jim Lemon <jim at bitwrit.com.au> wrote:
> John Kane wrote:
> > I clearly spoke too soon.
> >
> > With the actual data I am not getting sensible
> x-axis
> > units. The program with the actual data below.
> Graph
> > output is here:
> > http://ca.geocities.com/jrkrideau/R/hd.png .
> >
> > I seem to be getting only a single entry for the
> > x-axis of "2007". However dates range from
> > First Date Last Date
> > "2006-09-26" "2007-11-10"
> >
> > I must be missing something blindingly obvious but
> I
> > don't see it.
> >
> > Thanks for any suggestions.
> >
> >
> > Actual data and test program
> > ================================================
> > mydata <-
> >
>
read.table("http://ca.geocities.com/jrkrideau/R/heartdata.txt",
> > sep="\t",
> > header=FALSE)
> > mydata[,1] <- as.Date(mydata[,1],"%m/%d/%y")
> > names(mydata) <- Cs(dates, sy,dys,pulse, weight)
> > minmax <- c(max(mydata[,2]),min(mydata[,2]),
> > max(mydata[,3]),min(mydata[,3]))
> > names(minmax) <- c("maxsys", "minsys", "maxdsy",
> > "mindys") ; minmax
> >
> > min.max.dates <- c(min(mydata[,1]),
> max(mydata[,1]))
> > names(min.max.dates) <- c("First Date", "Last
> Date");
> > min.max.dates
> >
> > ss <- lm(mydata[,2]~mydata[,1])
> > plot(mydata[,1],mydata[,2], xlab="Dates",
> ylab="Blood
> > pressure",
> > ylim=c(minmax[4], minmax[1]), col= "red",
> > type="l")
> > abline (ss, col ="yellow")
> > dd <- lm(mydata[,3]~mydata[,1])
> > points(mydata[,1], mydata[,3], type="l",
> col="blue" )
> > abline(dd, col= "yellow", lwd=2)
> >
> >
> >
> Hi John,
>
> It can be done like this:
>
> plot(mydata[,1],mydata[,2], xlab="Dates",
> ylab="Blood
> pressure",ylim=c(minmax[4], minmax[1]), col=
> "red",
> type="l",xaxt="n")
> ...
> axisdates<-c("2006-11-01","2007-01-01","2007-03-01",
>
> "2007-05-01","2007-07-01","2007-09-01","2007-11-01")
> staxlab(at=as.Date(axisdates),labels=axisdates)
>
> Jim
>
More information about the R-help
mailing list