[R] XYPlot Conditioning Variable in Specific, Non-Alphanumeric Order. -- Resending with corrected .txt file

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Apr 1 15:51:17 CEST 2011


On Sat, Mar 19, 2011 at 2:53 AM, Guy Jett <GJett at itsi.com> wrote:
> Due to an error on my part, I have renamed the previously attached file from
>  T_5-04b_LTC-SE-SO-Compared.csv to
>  T_5-04b_LTC-SE-SO-Compared.txt.
> It remains a comma-delimited file so the extension can be changed and used per the script, or loaded separately.
> My sincere apologies,
> Guy
>
> -----Original Message-----
> From: Guy Jett
> Sent: Friday, March 18, 2011 1:13 PM
> To: 'r-help at R-project.org'
> Subject: XYPlot Conditioning Variable in Specific, Non-Alphanumeric Order.
>
> # I need to create an xyplot() where I control the specific order of #  both my conditioning variables.  The default code below plots the #  data correctly (dispersed across all 14 columns), but fails in two #  ways.  Both the primary conditioning variable (Transect), and the #  secondary conditioning variable (Offset) are in alphanumeric order, #  rather than the specific order I need.
>
> # Here is a call to the input datafile, which should be attached.  You may rename that .txt file to .csv for processing in the following line.
>    df <- read.csv(file = "T_5-04b_LTC-SE-SO-Compared.csv")
>
> # Basic default plot (correct data, incorrect layout):
>    xyplot((sbd+sed)/2 ~ Result | Offset+Transect, groups = PARLABEL, as.table = TRUE,
>    data = df,
>    layout = c(14,4), type = "b")
>
> # I attempted to control the order following the method described in #  the thread "[R] xyplot() - can you control how the plots are #  ordered?", but I appear to be missing, or misunderstanding #  something.  The modeled code is here.  It does put all the #  individual 'lattices'(?) in the needed order, BUT the graphics #  for the individual sets dump all the measurements into a single #  cell, on the diagonal, as if it's treating the conditioning #  variables as an [i,j] index.  Again not what I want.
>
> #  Draft code (incorrect data, correct layout):
>    Transects <- c("LNF02", "LSF02", "LUR01", "LURT1", "LUR03",
>                   "LUR05", "LUR09", "LUR11", "LUR12", "LUR15",
>                   "LUR16", "LUR21", "LURT3", "LUR25", "LURT4",
>                   "LUR28", "LUR36", "LUR38", "LUR46", "LURT5",
>                   "LUR48", "LLR04", "LLR10", "LLR11", "LLRT1",
>                   "LLR17", "LLRT2", "LLR18", "LLRT3", "LLR19")
>    Transects <- factor(Transects, levels = Transects)
>
>    Offsets <- c("T", "U", "V", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H")
>    Offsets <- factor(Offsets, levels = Offsets)
>
>    xyplot((sbd+sed)/2 ~ Result | Offsets+Transects, groups = PARLABEL, as.table = TRUE,
>    data = df,
>    layout = c(13,5), type = "b")
>
> # What I am looking for is a combination of the default plot, but ordered in #  the layout of the second code fragment.

You need to specify the order of the levels explicitly (to override
the default). Here is how to do it for one, you can similarly do the
other:

> levels(df$Offset)
 [1] "T" "U" "V" "Y" "Z" "A" "B" "C" "D" "E" "F" "G" "H"
> df$Offset <- factor(df$Offset,
+                     levels = c("T", "U", "V", "Y", "Z", "A",
+                                "B", "C", "D", "E", "F", "G", "H"))
> levels(df$Offset)
 [1] "T" "U" "V" "Y" "Z" "A" "B" "C" "D" "E" "F" "G" "H"

Once you make these changes, your original call should work as desired.

-Deepayan



More information about the R-help mailing list