[R] Simple plot() question
Andy Bunn
abunn at whrc.org
Tue Nov 16 16:13:32 CET 2004
Hi Mick:
I'm a little unsure if this is what you are after but does this do it?
foo.mat <- matrix(rnorm(100), nrow = 10, ncol = 10)
plot(foo.mat[1,], type="l", xlab = "Crud", ylab = "More Crud")
plot(foo.mat[1,order(foo.mat[1,])], type="l", xaxt = "n", xlab = "Crud",
ylab = "More Crud")
axis(1, at=1:length(foo.mat[1,]), labels= order(foo.mat[1,]))
Seems like a barplot might be a nice way to go too:
barplot(foo.mat[1,order(foo.mat[1,])], names.arg = order(foo.mat[1,]))
A reproducible example would help the list see what you are after as I might
be totally off on this.
HTH, Andy
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of michael watson
> (IAH-C)
> Sent: Tuesday, November 16, 2004 9:45 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Simple plot() question
>
>
> Hi
>
> First a simple question to do with plot(). How do I change the x-axis
> labels on a plot?
>
> For example, I am plotting each row of a matrix, and I want each row to
> be a line on my graph. Simple really. Eg:
>
> plot(sg[1,], type="l")
>
> When I do this, the x-axis is labelled 1:38, as I have 38 columns in my
> matrix. When I do:
>
> plot(sg[1,order(sg[1,])], type="l")
>
> Ideally I would like the x-axis labels to reflect the new order of the
> columns, but they're still numbered 1:38... I've read the plot() docs
> and the par() docs and can't figure it out - I know I'm missing
> something obvious, but what?
>
> Cheers
>
> Mick
>
> Michael Watson
> Head of Informatics
> Institute for Animal Health,
> Compton Laboratory,
> Compton,
> Newbury,
> Berkshire RG20 7NN
> UK
>
> Phone : +44 (0)1635 578411 ext. 2535
> Mobile: +44 (0)7990 827831
> E-mail: michael.watson at bbsrc.ac.uk
>
> ______________________________________________
> R-help at 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
More information about the R-help
mailing list