An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110106/e27daad7/attachment.pl>
Plotting Factors -- Sorting x-axis
3 messages · Taylor, Eric HLS:EX, David Winsemius, Bill Venables
On Jan 6, 2011, at 6:13 PM, Taylor, Eric HLS:EX wrote:
Hello; How do I plot these data in R without the Months being ordered alphabetically? Months Prec 1 Jan 102.1 2 Feb 69.7 3 Mar 44.7 4 Apr 32.1 5 May 24.0 6 Jun 18.7 7 Jul 14.0 8 Aug 20.0 9 Sep 32.4 10 Oct 58.9 11 Nov 94.5 12 Dec 108.2
Since they are most likely factor variables (but even if not): dfrm$Months <- factor(dfrm$Months, levels= month.abb) Then the level ordering will be as expected. David Winsemius, MD West Hartford, CT
That rather depends on what kind of plot you want to use.
Here is one option that you can use without any changes:
######
con <- textConnection("
Months Prec
1 Jan 102.1
2 Feb 69.7
3 Mar 44.7
4 Apr 32.1
5 May 24.0
6 Jun 18.7
7 Jul 14.0
8 Aug 20.0
9 Sep 32.4
10 Oct 58.9
11 Nov 94.5
12 Dec 108.2
")
tab <- read.table(con)
closeAllConnections()
rm(con)
with(tab, barplot(Prec, names = as.character(Months)))
#####
## If you want to adjust the factor so that the levels remain in natural months order, then
#####
tab <- within(tab,
Months <- factor(Months, levels = month.abb))
with(tab, barplot(Prec, names = levels(Months)))
######
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Taylor, Eric HLS:EX [Eric.Taylor at gov.bc.ca]
Sent: 07 January 2011 09:13
To: 'r-help at stat.math.ethz.ch'
Subject: [R] Plotting Factors -- Sorting x-axis
Sent: 07 January 2011 09:13
To: 'r-help at stat.math.ethz.ch'
Subject: [R] Plotting Factors -- Sorting x-axis
Hello;
How do I plot these data in R without the Months being ordered alphabetically?
Months Prec
1 Jan 102.1
2 Feb 69.7
3 Mar 44.7
4 Apr 32.1
5 May 24.0
6 Jun 18.7
7 Jul 14.0
8 Aug 20.0
9 Sep 32.4
10 Oct 58.9
11 Nov 94.5
12 Dec 108.2
Eric
Eric Taylor, Air Quality Meteorologist, Health Protection,
Ministry of Health Services
[[alternative HTML version deleted]]
______________________________________________
R-help at 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.