Changing the x-axis labels in plot()

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing the x-axis labels in plot()

michael watson (IAH-C)
Hi

Hopefully this one isn't in the manual or I am about to get shot :-S

One of my colleagues wants a slightly strange graph.  We basically have
a data matrix, and she wants to plot, for each row, the values in the
row as points on the graph.  The following code draws the graph just
fine:

plot(row(d)[,3:9],d[,3:9])

So as there are 12 rows in my matrix, there are 12 columns of points,
which is what she wants.

However, she wants the x-axis labelled with the row names, not with
1,2,3,4,5 etc

I can figure out from reading par() how to turn off the default drawing
of the numerical labels, but how do I use the row names instead?

Thanks
Mick

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Changing the x-axis labels in plot()

Bert Gunter
 

Please learn how to use R's extensive Help capabilities -- It **is** in the
"manual" -- and also in the R-help archives.

help.search('axis')  (obvious keyword, no?) will get you what you want.

-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA


> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> michael watson (IAH-C)
> Sent: Thursday, February 23, 2006 7:35 AM
> To: [hidden email]
> Subject: [R] Changing the x-axis labels in plot()
>
> Hi
>
> Hopefully this one isn't in the manual or I am about to get shot :-S
>
> One of my colleagues wants a slightly strange graph.  We
> basically have
> a data matrix, and she wants to plot, for each row, the values in the
> row as points on the graph.  The following code draws the graph just
> fine:
>
> plot(row(d)[,3:9],d[,3:9])
>
> So as there are 12 rows in my matrix, there are 12 columns of points,
> which is what she wants.
>
> However, she wants the x-axis labelled with the row names, not with
> 1,2,3,4,5 etc
>
> I can figure out from reading par() how to turn off the
> default drawing
> of the numerical labels, but how do I use the row names instead?
>
> Thanks
> Mick
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Changing the x-axis labels in plot()

Marc Schwartz (via MN)
In reply to this post by michael watson (IAH-C)
On Thu, 2006-02-23 at 15:35 +0000, michael watson (IAH-C) wrote:
> Hi
>
> Hopefully this one isn't in the manual or I am about to get shot :-S

Bang  ;-)

> One of my colleagues wants a slightly strange graph.  We basically have
> a data matrix, and she wants to plot, for each row, the values in the
> row as points on the graph.  The following code draws the graph just
> fine:
>
> plot(row(d)[,3:9],d[,3:9])


If I am understanding correctly what you want, you could alternatively
use:

  boxplot(as.data.frame(t(d[, 3:9])))

which provides a somewhat different approach to visualizing the data.
There are other methods as well of course.

> So as there are 12 rows in my matrix, there are 12 columns of points,
> which is what she wants.
>
> However, she wants the x-axis labelled with the row names, not with
> 1,2,3,4,5 etc
>
> I can figure out from reading par() how to turn off the default drawing
> of the numerical labels, but how do I use the row names instead?
>
> Thanks
> Mick


Try:

  plot(row(d)[,3:9], d[,3:9], xaxt = "n")


You can then use the axis() function to specify the labels and tick mark
positions that you want. See ?axis for more information.

In ?par, see 'xaxt' and 'yaxt', which are also referred to in the
description of the 'axes' argument in ?plot.default.

HTH,

Marc Schwartz

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Changing the x-axis labels in plot()

Duncan Murdoch
In reply to this post by michael watson (IAH-C)
On 2/23/2006 10:35 AM, michael watson (IAH-C) wrote:

> Hi
>
> Hopefully this one isn't in the manual or I am about to get shot :-S
>
> One of my colleagues wants a slightly strange graph.  We basically have
> a data matrix, and she wants to plot, for each row, the values in the
> row as points on the graph.  The following code draws the graph just
> fine:
>
> plot(row(d)[,3:9],d[,3:9])
>
> So as there are 12 rows in my matrix, there are 12 columns of points,
> which is what she wants.
>
> However, she wants the x-axis labelled with the row names, not with
> 1,2,3,4,5 etc
>
> I can figure out from reading par() how to turn off the default drawing
> of the numerical labels, but how do I use the row names instead?

Use the axis() function.  The x-axis is side=1; labels can be a
character vector containing anything you like.

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Changing the x-axis labels in plot()

Peter Dalgaard
In reply to this post by michael watson (IAH-C)
"michael watson (IAH-C)" <[hidden email]> writes:

> Hi
>
> Hopefully this one isn't in the manual or I am about to get shot :-S

*Kapow*... [1]
 

> One of my colleagues wants a slightly strange graph.  We basically have
> a data matrix, and she wants to plot, for each row, the values in the
> row as points on the graph.  The following code draws the graph just
> fine:
>  
> plot(row(d)[,3:9],d[,3:9])
>
> So as there are 12 rows in my matrix, there are 12 columns of points,
> which is what she wants.
>
> However, she wants the x-axis labelled with the row names, not with
> 1,2,3,4,5 etc
>
> I can figure out from reading par() how to turn off the default drawing
> of the numeri cal labels, but how do I use the row names instead?

axis(1, at=1:12, labels=rownames(d))


[1] Look e.g. at the examples section in plot.default.

--
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - ([hidden email])                  FAX: (+45) 35327907

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html