[R] x-axis (categorial variable) ordering with xyplot function (lattice package)

Jim Lemon jim at bitwrit.com.au
Thu Jul 25 01:56:30 CEST 2013

On 07/25/2013 12:17 AM, BLASER Arnaud wrote:
> Dear R mailing list readers,
> I am facing the following problem; for simplicity imagine I am working on a data frame of, say, 5 columns. The first column is a list of European countries, the other four are an index (continuous variable) of climate change impact under 4 different scenarios.
> ...
> However, when I try to use the code as above, R automatically re-order the x-axis (country) in alphabetical order. This was not unexpected, but I have spent the day (unsuccessfully) looking for a way to simply tell R not to do that and to keep the variable "country" as it is now ordered in the data frame to construct the x-axis of my plot. Is there any way to force it to keep the order as it is in the data frame ?
Hi Arnaud,
If you want a non-alphabetic ordering of factors, you will have to 
explicitly specify the order:

c("Austria","Belgium","Bulgaria","Czech Republic","United Kingdom"),
levels=c("Austria","Belgium","United Kingdom","Bulgaria",
"Czech Republic"))


More information about the R-help mailing list