[R] Trellis barchart, column display order issue
Deepayan Sarkar
deepayan at stat.wisc.edu
Tue Feb 15 23:02:42 CET 2005
On Tuesday 15 February 2005 14:57, Bock, Michael wrote:
> I have searched the archives and instructions high and low but have
> not found what I need.
>
> I have a dataframe named Data with columns:
> AdjResND0 - the numeric result
> Parameter - the classification (chemical name)
> Sort - the order I want the chemical names to appear, with leading
> zeros so all are the same length
> Client.Name - the sample name
Try looking at
levels(Data$Parameter)
I'll bet they are in alphabetical order. See ?factor for how to specify
the levels explicitly. Alternatively, barring unforeseen complications,
and assuming that you have a sufficiently modern version of R, you
should be able to do
barchart(AdjResND0 ~ reorder(Parameter, sort) | Client.Name,
Data, ...
and if that doesn't work as intended,
barchart(AdjResND0 ~ reorder(Parameter,
as.numeric(as.character(sort))) | Client.Name,
Data, ...
Deepayan
> I am trying to generate a series of 1 page barcharts, one for each
> sample. The dataframe has been sorted by Client.name and sort
> I use the following command:
>
> barchart(AdjResND0 ~ Parameter | Client.Name , Data,
> box.ratio = 0.8, ylab= ("Concentration (mg/kg)"),
> layout = c(0,1), scales = list(x="free",rot=90,cex = 0.5,
> axs = "i",abbreviate = TRUE ) )
>
> The parameters are listed alphabetic order from left to right in the
> bar chart so I constructed a new variable
> Label which is the sort and parameter variables concatenated
> together.
>
> barchart(AdjResND0 ~ Label | Client.Name , Data,
> box.ratio = 0.8, ylab= ("Concentration (mg/kg)"),
> layout = c(0,1), scales = list(x="free",rot=90,cex = 0.5,
> axs = "i",abbreviate = TRUE ) )
>
> This has everything in the correct order but obviously I don't want
> the column labels to have the sort order glued on the front. Any way
> to get the order I want and the labels I want?
>
> I am using :
> R : Copyright 2004, The R Foundation for Statistical Computing
> Version 2.0.1 (2004-11-15), ISBN 3-900051-07-0
>
> Under Windows XP
>
> Also, I am as yet unable to figure out how to get R to spool the
> graphs to a pdf file so I get all 30 graphs and I can save them for
> an appendix. I just want to be able to save all the graphs for future
> use, so I am not set on pdf or anything else. An example would be
> great!
>
>
>
> Thanks,
>
> Mike
>
>
>
> Michael J. Bock, PhD.
> ARCADIS
> 24 Preble St. Suite 100
> Portland, ME 04101
> 207.828.0046
> fax 207.828.0062
More information about the R-help
mailing list