[R] Help with Data Transformation

2011-01-10 Thread Guy Jett
Greetings,
I am new to R and am having trouble with parsing a file with the following 
characteristics:

* Individual results for a single sample are written to multiple lines.

* First 16 columns are constant from sample to sample.

* Remaining 10 need to be matched up (cross-tabbed?)

o   (the exact contents for the remaining 10 vary from sample to sample, as 
indicated in the extract below)

* Ultimate goal is to run various comparisons between the variable 
columns, compare samples from separate populations, and graph samples from the 
separate populations.

* (An extract is provided below)

The data is initially extracted from an SQL database into Excel, then saved as 
a tab-delimited text file for use in R.
I have been successful in using subset() to extract specific sample types, but 
have not yet been able to transform the data so that all the data needed is on 
a single line.  I have looked at several R manuals, read through 'R in a 
Nutshell', prowled the help resources (R Site Search and the Google link), 
tried stack(), subset(), reshape(), and several other functions, to no avail.

Thank you very much for your help.  This seems like a wonderful community,
Guy Jett, R.G.
Project Geologist
gj...@itsi.com<mailto:gj...@itsi.com>

Example Data Input (subset):
fldsampidCLP_ID  sacode  matrix   etc...  
prccodeLab EXMCODE   Analysis
PARLABELPARVQ Result
2268   LHR020GW-01E2   N WG 
   INOBRLS  NONEE300   CL   =   
  23590.9
2269   LHR020GW-01E2   N WG 
   INOBRLS  NONEE300   PO4ND  50
2270   LHR020GW-01E2   N WG 
   INOBRLS  NONEE300   SO4= 
22460
2272   LHR020GW-01E2   N WG 
   MET   BRLS  FLDFLT  E1631HG  = 
0.00171
2273   LHR020GW-01E2   N WG 
   MET   BRLS  FLDFLT  E1638AG  = 
2.57
2274   LHR020GW-01E2   N WG 
   MET   BRLS  FLDFLT  E1638AL   = 
122
2275   LHR020GW-01E2   N WG 
   MET   BRLS  FLDFLT  E1638AS   = 
317
2276   LHR020GW-01E2   N WG 
   MET   BRLS  FLDFLT  E1638B = 
9970
2289   LHR020GW-01E2   N WG 
   MET   BRLS  FLDFLT  E1638V = 
131
2290   LHR020GW-01E2   N WG 
   MET   BRLS  FLDFLT  E1638Zn   = 
1.76
2291   LHR020GW-01E2   N WG 
   MET   BRLS  METHOD  E1638PB   ND 
   0.008
2292   LHR020GW-01E2   N WG 
   MI  BRLS  NONEA2320ALK= 
807000
2293   LHR020GW-01E2   N WG 
   MI  BRLS  NONEA2320ALKB  = 
807000
2294   LHR020GW-01E2   N WG 
   MI  BRLS  NONEA2320ALKC  ND  2500
2295   LHR020GW-01E2   N WG 
   ORG   BRLS  NONEA5310B DOC   = 49330
2296   LHR020GW-01E2   N WG 
   SN  BRLS  NONEE300   NO3   = 
792
2326   LHR020SD-00E2 N SE   
MET   BRLS  METHOD  E1630MEHG   = 4.28
2327   LHR020SD-00E2 N SE   
MI  BRLS  METHOD  E160.3   SOLID= 
48.45
2328   LHR020SD-00E2 N SE   
ORG   BRLS  NONESW9060TOC= 
4.823
2329   LHR020SD-00E2 MY77J8 N SE   MET  
 A4SWMETHOD  C245.5   HG  = 5100
2330   LHR020SD-00E2 MY77J8 N SE   MET  
 A4SWMETHOD  E200.8   AG  ND   

Re: [R] Help with Data Transformation

2011-01-10 Thread Guy Jett
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, NA), .Label = c("", 
"", "Zn"), class = "factor"), X.3 = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, 2L), .Label = c("", 
"", "etc."), class = "factor"), X.4 = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, NA), .Label = c("", 
"", "ALK"), class = "factor"), X.5 = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, NA), .Label = c("", 
"", "ALKB"), class = "factor"), X.6 = structure(c(1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, NA), .Label = c("", 
"", "ALKC"), class = "factor"), X.7 = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, 2L), .Label = c("", 
"", "SOLID"), class = "factor"), X.8 = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, NA), .Label = c("", 
"", "DOC"), class = "factor"), X.9 = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, NA), .Label = c("", 
"", "TOC"), class = "factor"), X.10 = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, NA), .Label = c("", 
"", "NO3"), class = "factor")), .Names = c("X", "fldsampid", 
"CLP_ID", "sacode", "matrix", "etc.", "prccode", "Lab", "EXMCODE", 
"Analysis", "PARLABEL", "PARVQ", "Result", "X.1", "X.2", "X.3", 
"X.4", "X.5", "X.6", "X.7", "X.8", "X.9", "X.10"), class = "data.frame", 
row.names = c(NA, 
-30L))


-Original Message-
From: John Kane [mailto:jrkrid...@yahoo.ca] 
Sent: Monday, January 10, 2011 1:43 PM
To: r-help@r-project.org; Guy Jett
Subject: Re: [R] Help with Data Transformation

That sample data set is really hard to read.  Could you resent it after having 
used dput on it?  

A file output with dput is easily read into R and makes seeing what you need 
much easier.  BTW what are the = doing?

Thanks



--- On Mon, 1/10/11, Guy Jett  wrote:

> From: Guy Jett 
> Subject: [R] Help with Data Transformation
> To: "r-help@r-project.org" 
> Received: Monday, January 10, 2011, 3:59 PM Greetings, I am new to R 
> and am having trouble with parsing a file with the following 
> characteristics:
> 
> *         Individual results
> for a single sample are written to multiple lines.
> 
> *         First 16 columns
> are constant from sample to sample.
> 
> *         Remaining 10 need
> to be matched up (cross-tabbed?)
> 
> o   (the exact contents for the remaining 10 vary from sample to 
> sample, as indicated in the extract
> below)
> 
> *         Ultimate goal is to
> run various comparisons between the variable columns, compare samples 
> from separate populations, and graph samples from the separate 
> populations.
> 
> *         (An extract is
> provided below)
> 
> The data is initially extracted from an SQL database into Excel, then 
> saved as a tab-delimited text file for use in R.
> I have been successful in using subset() to extract specific sample 
> types, but have not yet been able to transform the data so that all 
> the data needed is on a single line.  I have looked at several R 
> manuals, read through 'R in a Nutshell', prowled the help resources (R 
> Site Search and the Google link), tried stack(), subset(), reshape(), 
> and several other functions, to no avail.
> 
> Thank you very much for your help.  This seems like a wonderful 
> community, Guy Jett, R.G.
> Project Geologist
> gj...@itsi.com<mailto:gj...@itsi.com>
> 
> Example Data Input (subset):
>                
> fldsampid
> CLP_ID  sacode
> matrix   etc...
> prccode
>   Lab
>    EXMCODE
>    Analysis
>       PARLABEL
>         PARVQ Result
> 2268       LHR020GW

Re: [R] Help with Data Transformation

2011-01-12 Thread Guy Jett
 ...
 $ LOGDATE  :Class 'Date'  num [1:19694] -717743 -717743 -717743 -717743 
-717743 ...
 $ sbd  : num  0 0 0 0 0 0 0 0 0 0 ...
 $ sed  : num  0 0 0 0 0 0 0 0 0 0 ...
 $ prccode  : Factor w/ 5 levels "INO","MET","MI",..: 2 2 2 2 2 2 2 2 2 2 ...
 $ Lab  : Factor w/ 5 levels "A4SW","BRLS",..: 2 2 2 2 2 2 2 2 2 2 ...
 $ EXMCODE  : Factor w/ 5 levels "FLDFLT","METHOD",..: 2 2 2 2 2 2 2 2 2 2 ...
 $ Analysis : Factor w/ 23 levels "A2320","A2540G",..: 10 11 12 12 12 12 12 12 
12 12 ...
 $ PARLABEL : Factor w/ 48 levels "AG","AL","ALK",..: 27 20 1 2 6 7 8 9 12 14 
...
 $ PARVQ: Factor w/ 3 levels "=","ND","TR": 1 1 2 1 1 1 1 2 1 1 ...
 $ Result   : num  20.6 24.7 5 14900 60 100 4930 4 182 80 ...
 $ RL   : num  3.1 0.77 10 5750 160 790 160 8 10 80 ...
 $ EPA_FLAGS: Factor w/ 10 levels "","J","J-","J+",..: 4 1 7 3 2 2 1 7 1 2 ...
 $ units: Factor w/ 3 levels "ug/kg","ug/L",..: 1 1 1 1 1 1 1 1 1 1 ...

2. "etc..." Sorry to confuse you, this was to indicate additional columns.

Guy Jett
ITSI,  A Gilbane Company
(925) 946-3340 Direct
(925) 457-4168 ITSI Cell
gj...@itsi.com

-Original Message-
From: John Kane [mailto:jrkrid...@yahoo.ca] 
Sent: Monday, January 10, 2011 4:29 PM
To: r-help@r-project.org; Guy Jett
Subject: RE: [R] Help with Data Transformation

That's fine.  Am I correct that this is the format you want for the output 
file? 
 
nams <- c("fldsampid", "CLP_ID", "sacode", "matrix", "etc.", "CL", "PO4", 
"SO4AG", "AL", "AS", "B", "V", "Zn", "etc.", "ALK", "ALKB", "ALKC", "SOLID", 
"DOC", "TOC", "NO3")


It seems a bit suspicious as you have etc. in there twice.


In any case if I understand what you want all you need to do is arrange those 
names in the order you want and put them in a vector call it bb.

Then you simply say

newxx <- xx[,bb]
et voilàI

You may want to have a look at indexing in the Introduction to R to get a 
feeling for what's happening herel

Below is a small example.

However I don't think your data.frame is quite what you think it is.

When I do str(xx) to look at the structure all your variables are being read in 
as factors, which I suspect is not what you want.  R tries to recognize what 
type of variable is being read in and often seems to decide a character or even 
a numeric variable is a factor

You may want to run the command
options(stringsAsFactors = FALSE)
before you load the data into the data.frame

I hope this is of some help.
#===
df1 <- structure(list(site = c(1, 1, 4, 4, 1, 4), id = structure(c(1L, 2L, 2L, 
3L, 1L, 2L), .Label = c("a", "b", "c"), class = "factor"),
cata = c(1, 1, 6, 1, 1, NA), catb = c(1, 2, 3, 4, 5, 6),
doga = c(3, 5, 3, 6, 4, 0), dogb = c(2, 4, 6, 8, 10, 12),
rata = c(NA, 9, 9, 8, 9, 8), ratb = c(1, 2, 3, 4, 5, 6),
bata = c(12, 42, NA, 45, 32, 54), batb = c(13, 15, 17, 19,
21, 23)), .Names = c("site", "id", "cata", "catb", "doga", "dogb", "rata", 
"ratb", "bata", "batb"), row.names = c("aa", "bb", "cc", "dd", "ee", "ff"), 
class = "data.frame")

df1

bb <- c("dogb", "rata", "ratb", "bata", "batb", "site", "id", "cata",
"catb", "doga")

newdf <- df1[,bb]

 
#==

--- On Mon, 1/10/11, Guy Jett  wrote:

> From: Guy Jett 
> Subject: RE: [R] Help with Data Transformation
> To: "John Kane" , "r-help@r-project.org" 
> 
> Received: Monday, January 10, 2011, 5:20 PM Thank you John, I have put 
> a copy of the dput file below my signature block.  I hope that is what 
> you need as I am unfamiliar with that function.  Note that empty cells 
> need to become "NA".
> The "=" character is part of the "PARVALUE" column.
> Yours,
> Guy
> gj...@itsi.com
> 
> structure(list(X = c(2268L, 2269L, 2270L, 2272L, 2273L, 2274L, 2275L, 
> 2276L, 2289L, 2290L, 2291L, 2292L, 2293L, 2294L, 2295L, 2296L, 2326L, 
> 2327L, 2328L, 2329L, 2330L, 2331L, 2332L, 2346L, 2349L, NA, NA, NA, 
> NA, NA), fldsampid = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
> 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L,

Re: [R] Help with Data Transformation - RESOLVED

2011-01-12 Thread Guy Jett
Hi Dennis,
SOLVED!!!

My thanks to both you, John, and others who chimed in.  Took a little more 
digging before finally working, but it is working!

Here's a little more of what I did and the ultimate resolutions:
I installed the reshape2 library from CRAN.
Executed
> (.packages())
[1] "reshape2"  "stats" "graphics"  "grDevices" "datasets"  "rcom"  
"rscproxy"  "utils" "methods"   "base"
confirming presence.
Executed your toy script (stepwise so as not to include the output as input)
Received the following result at the end:
> cast(df, idnum ~ lab, value = 'y')
Error: could not find function "cast"

The Package 'reshape2' documentation indicates that either acast() or dcast() 
are used, not giving an example of cast() itself.
I resolved this by trying both acast() and dcast().  Both yielded the same 
screen results.

Turning to my own data I was able to successfully execute the operation on one 
of my subsets AFTER, cleaning up some results with duplicates "PARLABELS".   
(throws the resulting matrix into a count of values but the docs give an 
indication of the resolution).  So it looks like I'm on my way after some 
further data clean-up.

I am using dcast() as I wish to stay 2-dimensional (personal limitations on 
brain()).

Cheers and thanks again to all,
Guy
ITSI,  A Gilbane Company
(925) 946-3340 Direct
(925) 457-4168 ITSI Cell
gj...@itsi.com<mailto:gj...@itsi.com>

From: Dennis Murphy [mailto:djmu...@gmail.com]
Sent: Wednesday, January 12, 2011 1:19 PM
To: Guy Jett
Cc: r-help@r-project.org
Subject: Re: [R] Help with Data Transformation

Hi:

This seems like a problem that is well suited for the cast() function in 
package reshape2. Here's a toy example:

library(reshape2)
df <- data.frame(idnum = rep(101:104, c(3, 2, 4, 3)),
  lab = unlist(sapply(c(3, 2, 4, 3), function(x) 
sample(LETTERS[1:6], x))),
  y = rpois(12, 7))
df
   idnum lab  y
1101   C  7
2101   F 11
3101   E  4
4102   B 10
5102   A  7
6103   E  6
7103   D  9
8103   B  3
9103   F 12
10   104   C 10
11   104   D  9
12   104   A  5
cast(df, idnum ~ lab, value = 'y')
  idnum  A  B  C  D  E  F
1   101 NA NA  7 NA  4 11
2   102  7 10 NA NA NA NA
3   103 NA  3 NA  9  6 12
4   104  5 NA 10  9 NA NA

Since you have multiple 'invariant' variables, you could use something like

cast(df, . ~ lab, value = 'y')

This would make all variables other than lab the 'rows', the values of lab as 
separate 'columns', with the value of the variable y inserted in the 
appropriate locations, NA fill otherwise.

cast() is an alternative to the reshape() function in base R.

HTH,
Dennis
On Wed, Jan 12, 2011 at 12:19 PM, Guy Jett 
mailto:gj...@itsi.com>> wrote:
Hi John,
Thank you for your patience.  I was away for a State certification exam 
yesterday, so am just getting back to this.

Reading through you response I believe I wasn't clear enough about what I'm 
trying to do.  Your description seems to rearrange the matrix without grouping 
the analytical results for a single sample onto a single line, as I had hoped.  
I may have confused things by attempting to send a truncated/simplified dataset.

Restatement of needs:
* I have 863 individual samples.  The following columns contain invariant 
results for each sample:
   - 
"Transect","Offset","Location","fldsampid","CLP_ID","sacode","matrix","LTCCODE",
   "Northing","Easting","CRDUNITS","Event","LOGDATE","sbd","sed".
   - Sorting can make use of "fldsampid" as these values are entirely unique to
 each sample.
* Each sample is associates with one or more of the following 48 analytical 
parameters:
   - 
AG","AL","ALK","ALKB","ALKC","AS","B","BA","BE","BR","CA","CD""CL","CO","CR","CU",
 
"DOC","FE","Hg","HG","HGACIDLAB","HGEXTINO","HGEXTORG","HGNONMOB""HGSEMIMOB","K",
 
"MEHG","MG","MN","MO","NH3N","NI","NO2N","NO3","NO3N","PB""PO4","S","SB","SE","SO4",
   "SOLID","SSC","TL","TOC","V","Zn","ZN"
   - These are currently stored in the "PARLABEL" column.
* For each sample ID I would like to create a single line;
 - Extract each "PARLAB

[R] XYPlot Conditioning Variable in Specific, Non-Alphanumeric Order.

2011-03-18 Thread Guy Jett
# 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.
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.

# Baring my likely misunderstanding of the example cited above,
#  there several comments in the help files that index.cond and/or
#  param.cond could be 'easily' used.  I have read the lattice help,
#  the lattice pdf, and many items in the R site help files.  The
#  use of these features remains a complete mystery to me, but
#  then, that doesn't surprise me at all.

# This should clean up anything created by the above scripts:
# Clean-up 
  rm(df, xLabel, yLabel, xlimit)

Thanks for all the help.
Cheers,
Guy Jett, R.G.
Project Geologist
gj...@itsi.com

__
R-help@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.


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

2011-04-01 Thread Guy Jett
Thank you very much Deepayan.  This does exactly what I needed!
Cheers,
Guy Jett
gj...@itsi.com

-Original Message-
From: Deepayan Sarkar [mailto:deepayan.sar...@gmail.com] 
Sent: Friday, April 01, 2011 6:51 AM
To: Guy Jett
Cc: r-help@R-project.org
Subject: Re: [R] XYPlot Conditioning Variable in Specific, Non-Alphanumeric 
Order. -- Resending with corrected .txt file


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
__
R-help@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.


[R] Placing Text on ggplot2 graphics vs. xyplot

2011-06-16 Thread Guy Jett
Greetings to the help mailing list.
I am in the process of translating a large graphic from xyplot to ggplot2 (13 
columns by about rows).
I have been unsuccessful trying to understand how to place the following text 
strings after three days of:
* Perusing  Wickham's "gg2plot" book;
* Searching his site for gg2plot and qplot;
* Reviewing the "man pages" for gg2plot;
* Searching the R archives.

Problems are:
* Translate the xyplot statement
   "xlab.top = c("long string",   gpar(fontsize = 10, fontface = "bold  x=0, 
y=-1, just = "left"))"
   to add a secondary x-axis to the top of my plot.
   (This may have something to do with "strip.text.x" but I just cannot make 
that work.  Trying
  several alternatives I keep getting error messages related to "Error in 
grobName(grob, prefix) :
  Invalid 'grob' argument", but "Error in grobName" didn't show up in 
searched of the archives.)


* Translate the xyplot statement
   "sub = c("not so long string, gpar(fontsize = 8, fontface = "plain",  
x=0.05, y=1, just = "left"))
   to add a "footer" to the plot.


* Split the lattice over multiple pages (each pages having three rows each) as 
xyplot allows using
   "layout = c(13,3)"
   (noting the ggplot2 "layout", such as vplayout, seems useful only for 
multiple plots on one screen /
  page rather than splitting a single plot over multiple pages.)
   (I could also do this by brute force, if needed.)

My thanks to all,
Guy Jett, R.G.
Project Geologist
ITSI,  A Gilbane Company

[[alternative HTML version deleted]]

__
R-help@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.


[R] Lattice xyplot to group by two parameters

2011-06-23 Thread Guy Jett
My thanks to this mailing list and its members for their great help in the 
past.  I have yet another question per the following code and comments:

# I need individual graphs grouped by "PARLABEL" AND "Event", with "PARLABEL"
#   controlling pct and lty, and "Event" controlling col (where Event==1 is 
green
#   and Event==2 is red). This is attempted in the xyplot parameter
#   "groups = c(PARLABEL, Event)". Current behavior appears to be that the
#   colors are controlled by "PARLABEL" along with the shape and line type.  
Some 
#   experimentation with those two parameters (reverse order, one or the other 
only)
#   suggests that the second parameter is ignored.
#
# I have also experimented with panel.superpose, subsetting, and Extended 
formula
#   interface, as appears to be suggested by the "man pages", but to no avail. 
#   
#   Note that I can get the graphics layout I need with ggplot2, but that has 
its
#   own issues with secondary axis and subtitle text placement, formatting, and 
#   pagination.
#
# Example script below.  Datafile included. 

  depthlimit=c(7,-1)
  xlimit=c(0.1,125000)
  TransectOrder = c("LLR19", "LLR18", "LLR17")

  OffsetOrder  =  c("T", "U", "V", "Y", "Z",
"A", "B", "C", "D", "E", "F", "G", "H")

# Parse the data for these plots -
  df <- read.csv(file = "5.04-r02_LTC-SE-SO-Compared.csv")
  df$Transect <- factor(df$Transect, levels = TransectOrder)
  levels(df$Transect)
  df$Offset <- factor(df$Offset, levels = OffsetOrder)
  levels(df$Offset)

xyplot((sbd+sed)/2 ~ Result | Offset+Transect, groups = c(PARLABEL, Event),
  as.table = TRUE,
  drop.unused.levels = FALSE, data = df,
  layout = c(13,3), type = "b",
  xlim = c(0.01, 122000), ylim = depthlimit,
  pch  =c(16, 18), cex = c(1, 1), # to be controlled by "PARLABEL"
  lty  =c("dashed", "solid"), # to be controlled by "PARLABEL"
  col = c("green", "red"),# to be controlled by "Event"
  scales = list(alternating = 1, x = list(rot = 45, log = TRUE)))

Yours,
Guy Jett, R.G.
Project Geologist
ITSI,  A Gilbane Company
gj...@itsi.com

__
R-help@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.