[R] plot with abscissa in hours/weekdays

2006-05-15 Thread m p
Hello,
How can I use plot and have abscissa in hours
say (20:00,22:00,00:00,02:00 etc) and also weekdays
say (Mon, Tue, Wed, ...) ?
Is there a command that I can put into
plot(xvec,yvec...,axes=...) that would enable that?
Thanks for help,
Mark

__
R-help@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


Re: [R] plot with abscissa in hours/weekdays

2006-05-15 Thread Ritwik Sinha

Hi,

You can use the axis() command.

For example

plot(xvec,yvec, xaxt=n)
axis(side=1, labels=c(Mon, Tue), at=c(0,1))

The xaxt sets up the axis but does not plot it. And axis does the rest.

Ritwik.
Case Western Reserve University
http://darwin.cwru.edu/~rsinha




m p wrote:

Hello,
How can I use plot and have abscissa in hours
say (20:00,22:00,00:00,02:00 etc) and also weekdays
say (Mon, Tue, Wed, ...) ?
Is there a command that I can put into
plot(xvec,yvec...,axes=...) that would enable that?
Thanks for help,
Mark

__
R-help@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

  


__
R-help@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

Re: [R] plot with abscissa in hours/weekdays

2006-05-15 Thread Gabor Grothendieck
On 5/15/06, m p [EMAIL PROTECTED] wrote:
 Hello,
 How can I use plot and have abscissa in hours
 say (20:00,22:00,00:00,02:00 etc) and also weekdays
 say (Mon, Tue, Wed, ...) ?
 Is there a command that I can put into
 plot(xvec,yvec...,axes=...) that would enable that?

I assume these are two different questions: (1) hours and (2) weekdays.
Here is some sample code.  See R News 4/1 Help Desk article for more
on dates.  Hopefully this will give you the idea and you can use this
as a base to make it even more sophisticated if you like.

# 1. chron times class test data
library(chron)
x - times(0:23/24)
y - (1:24)^2

# plot
plot(x, y, xaxt = n)
a - floor(24*min(x)):ceiling(24*max(x))
axis(1, a/24, a, cex.axis = 0.7)



# 2. Date class test data
library(chron)  # need is.weekend from chron to create data
xx - chron(1:100)
xx - as.Date(xx[!is.weekend(xx)])
yy - seq(length(xx))^2

# plot marking Mondays on the x axis
idx - 1:length(xx)
plot(idx, yy, xaxt = n, type = l)
is.monday - format(xx, %a) == Mon
lab - format(xx[is.monday], %b %d)
axis(1, which(is.monday), lab, cex.axis = 0.6, tcl = -0.6)
axis(1, idx, FALSE, tcl = -0.4)

__
R-help@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