[R] Plotting Factors -- Sorting x-axis

Bill.Venables at csiro.au Bill.Venables at csiro.au
Sat Jan 8 03:35:53 CET 2011


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

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.



More information about the R-help mailing list