[R] x axis labelling

2014-07-01 Thread Michael Millar
Hi,

I am new to R and am trying to create a graph with Time(24hr) along the x axis. 
Rather than start at 01.00, I wanted to start at 14.00.

I tried to use the axis(side=1, at=c(  )) function but it continues to put then 
in numeric order. Is there another way I can add labels to the x axis?

Thank You.

Michael
  
[[alternative HTML version deleted]]

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


Re: [R] x axis labelling

2014-07-01 Thread Michael Peng
Did you add xaxt = n in the plot function?

Try the following:
plot(x,y, xaxt = n)
axis(1, at = c(14, 20),labels = c(14h, 20h) )


2014-07-01 12:41 GMT-05:00 Michael Millar michael88mil...@hotmail.co.uk:

 Hi,

 I am new to R and am trying to create a graph with Time(24hr) along the x
 axis. Rather than start at 01.00, I wanted to start at 14.00.

 I tried to use the axis(side=1, at=c(  )) function but it continues to put
 then in numeric order. Is there another way I can add labels to the x axis?

 Thank You.

 Michael

 [[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


Re: [R] x axis labelling

2014-07-01 Thread Jim Lemon
On Tue, 1 Jul 2014 06:41:52 PM Michael Millar wrote:
 Hi,
 
 I am new to R and am trying to create a graph with Time(24hr) along 
the x
 axis. Rather than start at 01.00, I wanted to start at 14.00.
 
 I tried to use the axis(side=1, at=c(  )) function but it continues to put
 then in numeric order. Is there another way I can add labels to the x 
axis?
 
Hi Michael,
Perhaps this will get you out of trouble.

mmdat-data.frame(time=paste(c(14:23,0:13),00,sep=:),
 wind_speed=sample(0:30,24))
plot(mmdat$wind_speed,type=b,xaxt=n,xlab=Time)
axis(1,at=1:24,labels=mmdat$time)

If you want to get more tick labels on the time axis, look at staxlab 
(plotrix).

Jim

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


Re: [R] x axis labelling

2014-07-01 Thread Duncan Mackay
Hi Michael
Dates and times are always a problem as they are irregular not 1,2,3 ...,
100
If you want more fancy formatting of the x axis try this

First convert your time to a datetime class
# Use a dummy date for datetime as it is easier  
mmdat$time - seq(strptime(20140702 14, %Y%m%d %H), by = hours,
length= 24)
 # only gives numerical sequence on xlab
 plot(mmdat$wind_speed,type=b,xlab=Time)

However

 library(lattice)
 ?xyplot
# by starting at 15:00 hours get sequence and use formatting of dates 
xyplot(wind_speed ~time, data = mmdat,
type = b,
xlab=Time,
scales = list(x = list(at = seq(mmdat[2,1], by = 3 hours, length =
8),
   labels = format(seq(mmdat[2,1], by = 3
hours, length = 8),%H:%M)))
)

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Michael Millar
Sent: Wednesday, 2 July 2014 03:42
To: r-help@R-project.org
Subject: [R] x axis labelling

Hi,

I am new to R and am trying to create a graph with Time(24hr) along the x
axis. Rather than start at 01.00, I wanted to start at 14.00.

I tried to use the axis(side=1, at=c(  )) function but it continues to put
then in numeric order. Is there another way I can add labels to the x axis?

Thank You.

Michael
  
[[alternative HTML version deleted]]

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

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


Re: [R] x-axis labelling

2013-02-04 Thread Alfredo Tello
Hi Dave,

Thanks for your reply. I can't reproduce the last line of code your code.
The ifelse argument throws back an error saying it was not used.

A


On Fri, Feb 1, 2013 at 10:56 PM, David Winsemius dwinsem...@comcast.netwrote:


 On Feb 1, 2013, at 9:30 AM, Alfredo Tello wrote:

  Hi Folks!

 I have a question regarding an issue on which I´ve read a few threads but
 can´t resolve -- Labelling every other tick mark on the x-axis using
 factors. Here´s an example:

  Why not:

 db-data.frame(date=as.factor(**c(1:50)),var=rnorm(50))
 barplot(db$var,names.arg=**ifelse( rep( c(TRUE,FALSE),
 length=length(levels(db$date) ) ),  levels(db$date),
 ),las=2,cex.axis=0.8,cex=0.**8)

 barplot(db$var,names.arg=**ifelse( c(TRUE,FALSE),  levels(db$date),
 },las=2,cex.axis=0.8,cex=0.**8)


 -- David.

 This labels all the tickmarks in my barplot, which is the default
 behavior.
 I would like to label every other tick mark in the barplot --
 1,3,5,7 and so on.

 Thank you very much for your help!


 All the best,

 A

 --
 Alfredo Tello (http://alfredotello.com)
 Sustainable Aquaculture Group
 Institute of Aquaculture
 University of Stirling
 Scotland, UK.

 [[alternative HTML version deleted]]

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 David Winsemius, MD
 Alameda, CA, USA




-- 
Alfredo Tello (http://alfredotello.com)
Sustainable Aquaculture Group
Institute of Aquaculture
University of Stirling
Scotland, UK.

[[alternative HTML version deleted]]

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


Re: [R] x-axis labelling

2013-02-04 Thread David Winsemius

On Feb 4, 2013, at 4:00 AM, Alfredo Tello wrote:

 Hi Dave,
 
 Thanks for your reply. I can't reproduce the last line of code your code. The 
 ifelse argument throws back an error saying it was not used.

Did you look at your graphics window? On my machine the plot you asked for was 
created by the preceding line:

 
barplot(db$var, 
   names.arg=ifelse( rep( c(TRUE,FALSE), length=length(levels(db$date) ) ), 
 levels(db$date), ), 
   las=2,cex.axis=0.8,cex=0.8)

True, the line in question was copied to the message by mistake, but an 
arguably workable answer was presented.

-- 
David.

 
 A
 
 
 On Fri, Feb 1, 2013 at 10:56 PM, David Winsemius dwinsem...@comcast.net 
 wrote:
 
 On Feb 1, 2013, at 9:30 AM, Alfredo Tello wrote:
 
 Hi Folks!
 
 I have a question regarding an issue on which I´ve read a few threads but
 can´t resolve -- Labelling every other tick mark on the x-axis using
 factors. Here´s an example:
 
 Why not:
 
 db-data.frame(date=as.factor(c(1:50)),var=rnorm(50))
 barplot(db$var,names.arg=ifelse( rep( c(TRUE,FALSE), 
 length=length(levels(db$date) ) ),  levels(db$date), 
 ),las=2,cex.axis=0.8,cex=0.8)
 
 barplot(db$var,names.arg=ifelse( c(TRUE,FALSE),  levels(db$date), 
 },las=2,cex.axis=0.8,cex=0.8)
 
 
 -- David.
 This labels all the tickmarks in my barplot, which is the default behavior.
 I would like to label every other tick mark in the barplot --
 1,3,5,7 and so on.
 
 Thank you very much for your help!
 
 
 All the best,
 
 A
 
 -- 
 Alfredo Tello (http://alfredotello.com)
 Sustainable Aquaculture Group
 Institute of Aquaculture
 University of Stirling
 Scotland, UK.
 
 [[alternative HTML version deleted]]
 
 __
 R-help@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
 Alameda, CA, USA
 
 
 
 
 -- 
 Alfredo Tello (http://alfredotello.com)
 Sustainable Aquaculture Group
 Institute of Aquaculture
 University of Stirling
 Scotland, UK.

David Winsemius
Alameda, CA, USA

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


[R] x-axis labelling

2013-02-01 Thread Alfredo Tello
Hi Folks!

I have a question regarding an issue on which I´ve read a few threads but
can´t resolve -- Labelling every other tick mark on the x-axis using
factors. Here´s an example:

db-data.frame(date=as.factor(c(1:50)),var=rnorm(50))
barplot(db$var,names.arg=levels(db$date),las=2,cex.axis=0.8,cex=0.8)

This labels all the tickmarks in my barplot, which is the default behavior.
I would like to label every other tick mark in the barplot --
1,3,5,7 and so on.

Thank you very much for your help!


All the best,

A

-- 
Alfredo Tello (http://alfredotello.com)
Sustainable Aquaculture Group
Institute of Aquaculture
University of Stirling
Scotland, UK.

[[alternative HTML version deleted]]

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


Re: [R] x-axis labelling

2013-02-01 Thread David Winsemius


On Feb 1, 2013, at 9:30 AM, Alfredo Tello wrote:


Hi Folks!

I have a question regarding an issue on which I´ve read a few  
threads but

can´t resolve -- Labelling every other tick mark on the x-axis using
factors. Here´s an example:


Why not:

db-data.frame(date=as.factor(c(1:50)),var=rnorm(50))
barplot(db$var,names.arg=ifelse( rep( c(TRUE,FALSE),  
length=length(levels(db$date) ) ),  levels(db$date),  
),las=2,cex.axis=0.8,cex=0.8)


barplot(db$var,names.arg=ifelse( c(TRUE,FALSE),  levels(db$date),  
},las=2,cex.axis=0.8,cex=0.8)



-- David.
This labels all the tickmarks in my barplot, which is the default  
behavior.

I would like to label every other tick mark in the barplot --
1,3,5,7 and so on.

Thank you very much for your help!


All the best,

A

--
Alfredo Tello (http://alfredotello.com)
Sustainable Aquaculture Group
Institute of Aquaculture
University of Stirling
Scotland, UK.

[[alternative HTML version deleted]]

__
R-help@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
Alameda, CA, USA

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