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.

Country

2050B2

2050A2

2080B2

2080A2

Austria

-0.2

-0.6

...



Belgium

-0.2

-0.6





Bulgaria

-0.5

-0.8





Czech republic

-0.5

-0.8





United kingdom

-0.2

-0.6






I am using the package lattice to make a nice plot of the dots from the different scenario using the following code;

my.plot <- xyplot(2050B2+2050A2+2080B2+2080A2~country, data=my.dat,
scales=list(x=list(rot=45)))

note: the part "scales=list(x=list(rot=45))" is pure aesthetic here.

So far, so good. However, I wish to order the x-axis (countries) by grouping them by European region; i.e Austria, Belgium and United kingdom are western Europe, while Bulgaria and Czech republic are eastern Europe. In excel I added a new "region) variable (i.e 1 for Western Europe, 2 for eastern Europe) and I re-ordered my data frame according to this "region" variable.

I then imported this updated data frame in R, and checked how it looked with the usual code;

pot_dat <-read.csv(file.choose(),header=TRUE, sep=";",dec=".")
pot_dat

Again, so far so good; my second column ("country") is now ordered according to the values of the first column ("region").

Region

Country

2050B2

2050A2

2080B2

2080A2

1

Austria

-0.2

-0.6

...



1

Belgium

-0.2

-0.6





1

United Kingdom

-0.2

-0.6





2

Bulgaria

-0.5

-0.8





2

Czech republic

-0.5

-0.8







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 ?

Any help would be really welcomed !

Best,

Arnaud Blaser
PhD candidate
University of Neuchâtel
Institute of Economic Research (IRENE)
Pierre-à-Mazel 7
CH-2000 Neuchâtel


	[[alternative HTML version deleted]]

