[R] Accessing elements of a list

2011-05-25 Thread Seth W Bigelow
I have a list that is made of lists of varying length. I wish to create a 
new vector that contains the last element of each list. So far I have used 
sapply to determine the length of each list, but I'm stymied at the part 
where I index the list to make a new vector containing only the last item 
of each list

mylist = list(c(1,2,3),c(cat,dog),c(x,y,z,zz))  # Create 
list

last - sapply(mylist,length) # Make vector with list lengths 

last_only - mylist[[1:length(mylist)]][last]   # Crash and burn trying to 
make new vector with last items! 

How do I do this last step?


Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California
sbige...@fs.fed.us /  ph. 530 759 1718
[[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] Does POSIXlt extract date components properly?

2011-03-01 Thread Seth W Bigelow
I would like to use POSIX classes to store dates and extract components of 
dates. Following the example in Spector (Data Manipulation in R), I 
create a date

 mydate = as. POSIXlt('2005-4-19 7:01:00')

I then successfully extract the day with the command

 mydate$day
[1] 19

But when I try to extract the month

  mydate$mon
[1] 3

it returns the wrong month. And mydate$year is off by about 2,000 years. 
Am I doing something wrong?

Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California
sbige...@fs.fed.us /  ph. 530 759 1718
[[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] R implementation of S-distribution

2011-01-04 Thread Seth W Bigelow
I'm working with data that can exhibit either strong right- or left-skew. 
I understand the S-distribution is useful in such cases
(e.g., Voit and Schwacke, 2000. Random Number Generation from 
Right-Skewed, Symmetric, and Left-Skewed Distributions. Risk Analysis 20 
(1): 59-71).
Does anyone know of any R implementation of this distribution?


Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California
sbige...@fs.fed.us /  ph. 530 759 1718
[[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.


Re: [R] Doing operations by grouping variable

2010-09-21 Thread Seth W Bigelow
Thanks, Bill and Michael, you have answered the question I asked, but not 
the one I wished to ask
I want to obtain the maximum in each group of variables, so I could scale 
each variable by the maximum for its group. If I use tapply, as in the 
example below, there's a mismatch in dimensions of the output of tapply 
[5] and the data frame with the variables[25]. 


group = rep(1:5, each=5) # define grouping variable 

variable = rnorm(25)# 
generate data

d - data.frame(group,variable) # 
bundle together in a data frame

d$scaled - d$variable/(with(d,tapply(variable,group,max))) # 
crash and burn





Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California




bill.venab...@csiro.au 
09/20/2010 06:24 PM

To
michael.bedw...@gmail.com, sbige...@fs.fed.us, r-help@r-project.org
cc

Subject
RE: [R] Doing operations by grouping variable






That's if the variables are visible.  If they are only in the data frame 
it's not much more difficult

d - data.frame(group = rep(1:5, each=5), 
variable = rnorm(25))
with(d, tapply(variable, group, max))


(Tip: avoid using attach().)

Bill Venables. 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
On Behalf Of Michael Bedward
Sent: Tuesday, 21 September 2010 11:15 AM
To: Seth W Bigelow; Rhelp
Subject: Re: [R] Doing operations by grouping variable

Not sure why you think tapply is awkward. Your example would be...

group - rep(1:5, each=5)
variable - rnorm(25)
tapply(variable, group, max)

...which looks quite elegant to me :)

Meanwhile, the reason your expression doesn't work is that you are
asking mistakenly for elements 1:5 repeatedly from the variable col.
If you just type d$variable[ d$group ] and compare the values to your
variable vector this should be clear.

Michael

On 21 September 2010 10:59, Seth W Bigelow sbige...@fs.fed.us wrote:
 I'm writing an expression that requires searching a vector according to
 group. As an example, I want to find the maximum value in each of 5
 groups.


 group=rep(1:5, each=5)  # create grouping 
variable

 variable=rnorm(25)  # generate data

 d - data.frame(group,variable) # make data 
frame

 max(d$variable[d$group])# try expression that
 doesn't work

 I'm expecting a vector containing the maximum variable value, per group.
 What am I doing wrong? I know I can use aggregate, tapply, etc. but that
 seems awkward and bulky, is there a simpler way?


 Dr. Seth  W. Bigelow
 Biologist, USDA-FS Pacific Southwest Research Station
 1731 Research Park Drive, Davis California

[[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-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.


[[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.


Re: [R] Doing operations by grouping variable

2010-09-21 Thread Seth W Bigelow
Bill, 

I'd never heard of ave( ) before, but it works like a charm for the 
purpose outlined below

Thanks!!


Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California




William Dunlap wdun...@tibco.com 
09/21/2010 08:52 AM

To
Seth W Bigelow sbige...@fs.fed.us, R-help R-help@r-project.org
cc

Subject
RE: [R] Doing operations by grouping variable






Have you tried using ave()?
  group - rep(1:5,each=5)
  variable - log(1:25)
  d - data.frame(group, variable)
  d$scaled - d$variable/with(d, ave(variable, group, FUN=max))

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Seth W Bigelow
 Sent: Tuesday, September 21, 2010 8:43 AM
 To: bill.venab...@csiro.au
 Cc: r-help@r-project.org
 Subject: Re: [R] Doing operations by grouping variable
 
 Thanks, Bill and Michael, you have answered the question I 
 asked, but not 
 the one I wished to ask
 I want to obtain the maximum in each group of variables, so I 
 could scale 
 each variable by the maximum for its group. If I use tapply, 
 as in the 
 example below, there's a mismatch in dimensions of the output 
 of tapply 
 [5] and the data frame with the variables[25]. 
 
 
 group = rep(1:5, each=5) # define grouping variable 
 
 variable = rnorm(25) 
   # 
 generate data
 
 d - data.frame(group,variable) 
   # 
 bundle together in a data frame
 
 d$scaled - d$variable/(with(d,tapply(variable,group,max))) 
   # 
 crash and burn
 
 
 
 
 
 Dr. Seth  W. Bigelow
 Biologist, USDA-FS Pacific Southwest Research Station
 1731 Research Park Drive, Davis California
 
 
 
 
 bill.venab...@csiro.au 
 09/20/2010 06:24 PM
 
 To
 michael.bedw...@gmail.com, sbige...@fs.fed.us, 
 r-help@r-project.org
 cc
 
 Subject
 RE: [R] Doing operations by grouping variable
 
 
 
 
 
 
 That's if the variables are visible.  If they are only in the 
 data frame 
 it's not much more difficult
 
 d - data.frame(group = rep(1:5, each=5), 
 variable = rnorm(25))
 with(d, tapply(variable, group, max))
 
 
 (Tip: avoid using attach().)
 
 Bill Venables. 
 
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] 
 On Behalf Of Michael Bedward
 Sent: Tuesday, 21 September 2010 11:15 AM
 To: Seth W Bigelow; Rhelp
 Subject: Re: [R] Doing operations by grouping variable
 
 Not sure why you think tapply is awkward. Your example would be...
 
 group - rep(1:5, each=5)
 variable - rnorm(25)
 tapply(variable, group, max)
 
 ...which looks quite elegant to me :)
 
 Meanwhile, the reason your expression doesn't work is that you are
 asking mistakenly for elements 1:5 repeatedly from the variable col.
 If you just type d$variable[ d$group ] and compare the values to your
 variable vector this should be clear.
 
 Michael
 
 On 21 September 2010 10:59, Seth W Bigelow sbige...@fs.fed.us wrote:
  I'm writing an expression that requires searching a vector 
 according to
  group. As an example, I want to find the maximum value in each of 5
  groups.
 
 
  group=rep(1:5, each=5)  # create grouping 
 variable
 
  variable=rnorm(25)  # generate data
 
  d - data.frame(group,variable) # make data 
 frame
 
  max(d$variable[d$group])# try 
 expression that
  doesn't work
 
  I'm expecting a vector containing the maximum variable 
 value, per group.
  What am I doing wrong? I know I can use aggregate, tapply, 
 etc. but that
  seems awkward and bulky, is there a simpler way?
 
 
  Dr. Seth  W. Bigelow
  Biologist, USDA-FS Pacific Southwest Research Station
  1731 Research Park Drive, Davis California
 
 [[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-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.
 
 
[[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.
 


[[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

Re: [R] Doing operations by grouping variable

2010-09-21 Thread Seth W Bigelow
Aah, that is the sort of truly elegant solution I have been seeking. And 
it's wrapped up in a nice programming shortcut to boot (i.e., the within 
statement). I retract anything I may have said about tapply being clunky.

Many thanks

--Seth

Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California




bill.venab...@csiro.au 
09/21/2010 03:15 PM

To
sbige...@fs.fed.us
cc
michael.bedw...@gmail.com, r-help@r-project.org
Subject
RE: [R] Doing operations by grouping variable






You left out the subscript.  Why not just do

d - within(data.frame(group = rep(1:5, each = 5), variable = rnorm(25)), 
 scaled - variable/tapply(variable, group, max)[group])

and be done with it?

(Warning: if you replace the second '-' above by '=', it will not work. 
It is NOT true that you can always replace '-' by '=' for assignment. 
Why?)

Bill Venables.

-Original Message-
From: Seth W Bigelow [mailto:sbige...@fs.fed.us] 
Sent: Wednesday, 22 September 2010 1:43 AM
To: Venables, Bill (CMIS, Cleveland)
Cc: michael.bedw...@gmail.com; r-help@r-project.org
Subject: RE: [R] Doing operations by grouping variable


Thanks, Bill and Michael, you have answered the question I asked, but not 
the one I wished to ask I want to obtain the maximum in each group of 
variables, so I could scale each variable by the maximum for its group. If 
I use tapply, as in the example below, there's a mismatch in dimensions of 
the output of tapply [5] and the data frame with the variables[25]. 


group - rep(1:5, each=5) # define grouping variable

variable - rnorm(25) # generate data 

d - data.frame(group,variable)   # bundle together in a data frame 

d$scaled - d$variable/(with(d,tapply(variable,group,max)))# crash and 
burn 





Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California




bill.venab...@csiro.au 

09/20/2010 06:24 PM 

 
To
 michael.bedw...@gmail.com, sbige...@fs.fed.us, 
r-help@r-project.org 
cc
 
Subject
 RE: [R] Doing operations by grouping variable

 




That's if the variables are visible.  If they are only in the data frame 
it's not much more difficult

d - data.frame(group = rep(1:5, each=5), 
   variable = rnorm(25))
with(d, tapply(variable, group, max))


(Tip: avoid using attach().)

Bill Venables. 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
On Behalf Of Michael Bedward
Sent: Tuesday, 21 September 2010 11:15 AM
To: Seth W Bigelow; Rhelp
Subject: Re: [R] Doing operations by grouping variable

Not sure why you think tapply is awkward. Your example would be...

group - rep(1:5, each=5)
variable - rnorm(25)
tapply(variable, group, max)

...which looks quite elegant to me :)

Meanwhile, the reason your expression doesn't work is that you are
asking mistakenly for elements 1:5 repeatedly from the variable col.
If you just type d$variable[ d$group ] and compare the values to your
variable vector this should be clear.

Michael

On 21 September 2010 10:59, Seth W Bigelow sbige...@fs.fed.us wrote:
 I'm writing an expression that requires searching a vector according to
 group. As an example, I want to find the maximum value in each of 5
 groups.


 group=rep(1:5, each=5)  # create grouping 
variable

 variable=rnorm(25)  # generate data

 d - data.frame(group,variable) # make data 
frame

 max(d$variable[d$group])# try expression that
 doesn't work

 I'm expecting a vector containing the maximum variable value, per group.
 What am I doing wrong? I know I can use aggregate, tapply, etc. but that
 seems awkward and bulky, is there a simpler way?


 Dr. Seth  W. Bigelow
 Biologist, USDA-FS Pacific Southwest Research Station
 1731 Research Park Drive, Davis California

[[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 
https://stat.ethz.ch/mailman/listinfo/r-help 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
http://www.r-project.org/posting-guide.html 
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
https://stat.ethz.ch/mailman/listinfo/r-help 
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
http://www.r-project.org/posting-guide.html 



[[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

[R] Doing operations by grouping variable

2010-09-20 Thread Seth W Bigelow
I'm writing an expression that requires searching a vector according to 
group. As an example, I want to find the maximum value in each of 5 
groups.


group=rep(1:5, each=5)  # create grouping variable 
 
variable=rnorm(25)  # generate data

d - data.frame(group,variable) # make data frame

max(d$variable[d$group])# try expression that 
doesn't work

I'm expecting a vector containing the maximum variable value, per group. 
What am I doing wrong? I know I can use aggregate, tapply, etc. but that 
seems awkward and bulky, is there a simpler way?


Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California
 
[[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 legend

2010-06-22 Thread Seth W Bigelow
I have a moderately complex graph with three panels. There are data points 
plotted, and fitted lines are added using a panel function, which includes 

with(alt.data[[which.packet()[1]]] statements. It all graphs out 
beautifully, but none of the usual tricks to get the proper legend to plot 
are working, i.e., using auto.key, key, etc.
One message I keep getting is
 
Error in key[[i]][[1]] - NULL :  more elements supplied than there are to 
replace



Any suggestions will be appreciated

--Seth


Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis Californiayear,survey,tx,bk,dayt,t,CC,doy,dep
2007,1,Control,Tamarack,2007-07-26,0.06356556,72,207,0-15
2007,2,Control,Tamarack,2007-08-30,0.03400111,72,242,0-15
2007,3,Control,Tamarack,2007-09-26,0.1054356,72,269,0-15
2007,1,50% target,Tamarack,2007-07-26,0.1115322,57,207,0-15
2007,2,50% target,Tamarack,2007-08-30,0.07165444,57,242,0-15
2007,3,50% target,Tamarack,2007-09-26,0.1154533,57,269,0-15
2007,1,30% target,Tamarack,2007-07-26,0.0654,40.25,207,0-15
2007,2,30% target,Tamarack,2007-08-30,0.03566778,40.25,242,0-15
2007,3,30% target,Tamarack,2007-09-26,0.0729,40.25,269,0-15
2007,1,Group,Tamarack,2007-07-26,0.147,6.11,207,0-15
2007,2,Group,Tamarack,2007-08-30,0.10344,6.11,242,0-15
2007,3,Group,Tamarack,2007-09-26,0.1612267,6.11,269,0-15
2007,1,Control,Deanes,2007-07-24,0.09867445,79,205,0-15
2007,2,Control,Deanes,2007-08-28,0.08022,79,240,0-15
2007,3,Control,Deanes,2007-09-24,0.1117922,79,267,0-15
2007,1,50% target,Deanes,2007-07-24,0.11711,51.5,205,0-15
2007,2,50% target,Deanes,2007-08-28,0.08067111,51.5,240,0-15
2007,3,50% target,Deanes,2007-09-24,0.1418667,51.5,267,0-15
2007,1,30% target,Deanes,2007-07-24,0.07089889,52.75,205,0-15
2007,2,30% target,Deanes,2007-08-28,0.04844556,52.75,240,0-15
2007,3,30% target,Deanes,2007-09-24,0.06822444,52.75,267,0-15
2007,1,Group,Deanes,2007-07-24,0.1215567,12.46,205,0-15
2007,2,Group,Deanes,2007-08-28,0.07945333,12.46,240,0-15
2007,3,Group,Deanes,2007-09-24,0.131,12.46,267,0-15
2007,1,Control,Pineleaf,2007-07-25,0.08367222,79.5,206,0-15
2007,2,Control,Pineleaf,2007-08-29,0.07334333,79.5,241,0-15
2007,1,50% target,Pineleaf,2007-07-25,0.09167111,62.63,206,0-15
2007,2,50% target,Pineleaf,2007-08-29,0.06644556,62.63,241,0-15
2007,3,50% target,Pineleaf,2007-09-25,0.07610778,62.63,268,0-15
2007,1,30% target,Pineleaf,2007-07-25,0.1068889,54.25,206,0-15
2007,2,30% target,Pineleaf,2007-08-29,0.08655111,54.25,241,0-15
2007,1,Group,Pineleaf,2007-07-25,0.06344667,18.84,206,0-15
2007,2,Group,Pineleaf,2007-08-29,0.04310889,18.84,241,0-15
2007,3,Group,Pineleaf,2007-09-25,0.07510889,18.84,268,0-15
2007,1,Control,Tamarack,2007-07-26,0.0968,72,207,15-40
2007,2,Control,Tamarack,2007-08-30,0.0902,72,242,15-40
2007,3,Control,Tamarack,2007-09-26,0.107,72,269,15-40
2007,1,50% target,Tamarack,2007-07-26,0.141,57,207,15-40
2007,2,50% target,Tamarack,2007-08-30,0.119,57,242,15-40
2007,3,50% target,Tamarack,2007-09-26,0.1127778,57,269,15-40
2007,1,30% target,Tamarack,2007-07-26,0.105,40.25,207,15-40
2007,2,30% target,Tamarack,2007-08-30,0.0867,40.25,242,15-40
2007,3,30% target,Tamarack,2007-09-26,0.0978,40.25,269,15-40
2007,1,Group,Tamarack,2007-07-26,0.238,6.11,207,15-40
2007,2,Group,Tamarack,2007-08-30,0.2187778,6.11,242,15-40
2007,3,Group,Tamarack,2007-09-26,0.2258889,6.11,269,15-40
2007,1,Control,Deanes,2007-07-24,0.185,79,205,15-40
2007,2,Control,Deanes,2007-08-28,0.178,79,240,15-40
2007,3,Control,Deanes,2007-09-24,0.1935556,79,267,15-40
2007,1,50% target,Deanes,2007-07-24,0.161,51.5,205,15-40
2007,2,50% target,Deanes,2007-08-28,0.1356667,51.5,240,15-40
2007,3,50% target,Deanes,2007-09-24,0.127,51.5,267,15-40
2007,1,30% target,Deanes,2007-07-24,0.207,52.75,205,15-40
2007,2,30% target,Deanes,2007-08-28,0.1745,52.75,240,15-40
2007,3,30% target,Deanes,2007-09-24,0.1926667,52.75,267,15-40
2007,1,Group,Deanes,2007-07-24,0.253,12.46,205,15-40
2007,2,Group,Deanes,2007-08-28,0.2568889,12.46,240,15-40
2007,3,Group,Deanes,2007-09-24,0.257,12.46,267,15-40
2007,1,Control,Pineleaf,2007-07-25,0.156,79.5,206,15-40
2007,2,Control,Pineleaf,2007-08-29,0.125125,79.5,241,15-40
2007,1,50% target,Pineleaf,2007-07-25,0.1175,62.63,206,15-40
2007,2,50% target,Pineleaf,2007-08-29,0.11525,62.63,241,15-40
2007,3,50% target,Pineleaf,2007-09-25,0.127375,62.63,268,15-40
2007,1,30% target,Pineleaf,2007-07-25,0.235,54.25,206,15-40
2007,2,30% target,Pineleaf,2007-08-29,0.19775,54.25,241,15-40
2007,1,Group,Pineleaf,2007-07

Re: [R] Lattice legend

2010-06-22 Thread Seth W Bigelow
Here is the code for my recent query:
The first part just sets up the data. It's the last part 
titled individual depth graph where the actual graphics code comes in

Thx
--Seth



library(lattice)
setwd(c:/sethdocs/3 Light and PLAS txs/8 Figures/Fg 6 Soil wetness)

d - read.table(2007 data.txt, header=TRUE, sep = ,)
str(d)
CC - rep(6:96,3)
depth - rep(1:3, each=91)
g - data.frame(depth, CC)


### 0 - 15 PRE parms 

model - function(a, b, f, CC){
t - a + exp(f-(b*CC))
return(t)
}

a = 0.08
b = 0.275
f = -1.18

g$t - ifelse(g$depth==1,round(model(a, b, f, g$CC),3),g$t==NA)

# g$depth = rep(0-15,nrow(g))

### 15 - 40 PRE parms ##

a  - 0.14
b  - 0.0683
f  - -1.9

g$t  - ifelse(g$depth==2, round(model(a, b, f, g$CC),3),g$t)

### 40 - 70 PRE parms, graphs ##

a - 0.291
b - -0.00094
}
a - 0.25
g$t - ifelse(g$depth==3, a, g$t)

s - split(g, depth)

 Individual depth graph ###

sup.sym - Rows(trellis.par.get(superpose.symbol),1:4)
sup.sym
sup.sym$pch[1:4] - c(6,2,0,1)

# show.settings()

mypanel - function(..., alt.data){
panel.xyplot(...)
with(alt.data[[which.packet()[1]]], # 'with' evaluates 
statement and includes with version of dataset in local workspace
  panel.xyplot(x = CC, y = t, type=l, col=black))
}

graf - xyplot(t~CC|dep,d, groups=tx, alt.data=s, 
pch = sup.sym$pch, 
cex=1.5,# symbol 
size
layout = c(3,1),
xlab = list(Canopy cover (%), cex=1.7),
ylab = list(expression(paste(soil moisture 
(m^{3},/m^{3},))), 
cex=1.2),
scales=list(x = list(cex=1.3), y = list(cex=1.3)),
strip = strip.custom(bg=transparent),
panel = mypanel,
key = list(
text = c(heavy thin,light thin, control, group), 
columns=2,
points=list(pch=sup.sym)
),
aspect=xy)
graf



Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California




Felix Andrews fe...@nfrac.org 
Sent by: foolish.andr...@gmail.com
06/22/2010 04:29 PM

To
Seth W Bigelow sbige...@fs.fed.us
cc

Subject
Re: [R] Lattice legend






Plase post your code (to the list). We can't help if we don't know
what you are doing.

Cheers
-Felix

On 23 June 2010 08:54, Seth W Bigelow sbige...@fs.fed.us wrote:
 I have a moderately complex graph with three panels. There are data 
points
 plotted, and fitted lines are added using a panel function, which 
includes

 with(alt.data[[which.packet()[1]]] statements. It all graphs out
 beautifully, but none of the usual tricks to get the proper legend to 
plot
 are working, i.e., using auto.key, key, etc.
 One message I keep getting is

 Error in key[[i]][[1]] - NULL :  more elements supplied than there are 
to
 replace



 Any suggestions will be appreciated

 --Seth


 Dr. Seth  W. Bigelow
 Biologist, USDA-FS Pacific Southwest Research Station
 1731 Research Park Drive, Davis California
 __
 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.





-- 
Felix Andrews / 安福立
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andr...@anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/

year,survey,tx,bk,dayt,t,CC,doy,dep
2007,1,Control,Tamarack,2007-07-26,0.06356556,72,207,0-15
2007,2,Control,Tamarack,2007-08-30,0.03400111,72,242,0-15
2007,3,Control,Tamarack,2007-09-26,0.1054356,72,269,0-15
2007,1,50% target,Tamarack,2007-07-26,0.1115322,57,207,0-15
2007,2,50% target,Tamarack,2007-08-30,0.07165444,57,242,0-15
2007,3,50% target,Tamarack,2007-09-26,0.1154533,57,269,0-15
2007,1,30% target,Tamarack,2007-07-26,0.0654,40.25,207,0-15
2007,2,30% target,Tamarack,2007-08-30,0.03566778,40.25,242,0-15
2007,3,30% target,Tamarack,2007-09-26,0.0729,40.25,269,0-15
2007,1,Group,Tamarack,2007-07-26,0.147,6.11,207,0-15
2007,2,Group,Tamarack,2007-08-30,0.10344,6.11,242,0-15
2007,3,Group,Tamarack,2007-09-26,0.1612267,6.11,269,0-15
2007,1,Control,Deanes,2007-07-24,0.09867445,79,205,0-15
2007,2,Control,Deanes,2007-08-28,0.08022,79,240,0-15
2007,3,Control,Deanes,2007-09-24,0.1117922,79,267,0-15
2007,1,50% target,Deanes,2007-07-24,0.11711,51.5,205,0-15
2007,2,50% target,Deanes,2007-08-28,0.08067111,51.5,240,0-15
2007,3,50% target,Deanes,2007-09-24,0.1418667,51.5,267,0-15
2007,1,30% target,Deanes,2007-07-24,0.07089889,52.75,205,0-15

[R] Re : Eliminate border in wireframe plot

2010-03-16 Thread Seth W Bigelow
Scott:

This may work for you. Just include the statement
par.settings - par.set1 in your wire graph statement

par.set1 -list(
axis.line=list(col=transparent),  # Get rid 
of box around fig?
clip=list(panel=FALSE), # disarm 
lurking panel settings?
 
)



Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California
sbige...@fs.fed.us /  ph. 530 759 1718
[[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.


Re: [R] Eliminate border in wireframe plot

2010-03-16 Thread Seth W Bigelow
Scott, I asked this same question a few years back, here's what Deepayan 
wrote. I think the last hint about scales will help you
--Seth

On 5/9/07, Seth W Bigelow sbige...@fs.f... wrote: 
 
 I would like to remove the outermost box from my wireframe plots -- this 
is 
 the box that is automatically generated, and is not the inner cube that 
 frames the data. There was a thread on this 4 yrs ago but none of the 
fixes 
 work (e.g., grid.newpage(), grid.lines(gp = gpar(col = NA)) or 
 par.box=list(col=1),col=NA. These just make the data or the cube 
disappear. 
 Has anyone solved this issue? 
 Here's some sample code. In case you are wondering, I have indeed 
purchased 
 Paul Murrel's book. 

But have you looked at example(wireframe)? The last example is what 
you want. You might also want to add 

scales = list(col = black) 

to the call. 

-Deepayan 



Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California
sbige...@fs.fed.us /  ph. 530 759 1718



Waichler, Scott R scott.waich...@pnl.gov 
03/16/2010 05:12 PM

To
Seth W Bigelow sbige...@fs.fed.us
cc

Subject
RE: R-help Digest, Vol 85, Issue 16






Seth,
 
Thank for you for the suggestion.  I found that the axis.line setting does 
get rid of the panel border, but unfortunately also the tick marks that go 
with the bounding box (but not the bounding box itself).  The clip command 
doesn?t seem to do anything. 
 
Below is the code I?m using for testing.
 
Scott Waichler
 
 
#  Test script for figuring out how to use contour3d and wireframe 
together.
#
#  source(/projects/rifle/scripts/test_3d.r)
 
library(lattice)
library(misc3d)
 
xlim - c(7, 18)
ylim - c(0, 10)
zlim - c(1613.22, 1619.52)
z.ticks - rev(seq(gs, wasatch, by=-1))
z.tick.labels - gs - z.ticks
 
pdf(file = ?test_3d.pdf, paper=special, width=7.5, height=6, 
pointsize=12)
 
# Note about screen settings, which determine point of view:  After each 
rotation, new axes are defined for
# the next rotation as at the start:  x is to the right of the 2D view, y 
is towards the top, and z
# is positive out of the page towards you.  Rotations follow the 
right-hand rule:  positive angles follow
# curved fingers of right hand, with thumb pointing in positive direction 
of associated axis. 
w - wireframe(matrix(zlim[1], 2, 2) ~ rep(xlim,2)*rep(ylim,each=2),
   xlim = xlim, ylim = ylim, zlim = zlim,
   aspect=c(diff(ylim) / diff(xlim), diff(zlim) / diff(xlim)),
   xlab = X (m), ylab = Y (m), zlab = Z (m),
   scales = list(arrows = FALSE, z=list(at = z.ticks, labels = 
z.tick.labels)),
   #zoom=1.05,
   panel.aspect=0.75,
   par.settings = list(#box.3d = list(col = transparent, alpha = 0), 
 # remove the axes
   axis.line = list(col = transparent) # remove 
the panel border
  ), 
   #screen=list(x=-90, y=-40),  # looking from side
   screen=list(x=-100, y=-40, z=5),  # looking from side and slightly 
up
   main=Testing with /projects/rifle/scripts/test_3d.r, 
   panel.3d.wireframe = function(x, y, z, rot.mat, distance,
xlim.scaled, ylim.scaled,
zlim.scaled, ...) {
 scale - c(diff(xlim.scaled) / diff(xlim),
diff(ylim.scaled) / diff(ylim),
diff(zlim.scaled) / diff(zlim))
 shift - c(mean(xlim.scaled) - mean(xlim) * scale[1],
mean(ylim.scaled) - mean(ylim) * scale[2],
mean(zlim.scaled) - mean(zlim) * scale[3])
 if(!is.na((isoc[[nc]][[ic]][[j]])[1])) {
   P - rbind(cbind(diag(scale), shift), c(0, 0, 0, 1))
   rot.mat - rot.mat %*% P
   #drawScene(isoc[[nc]][[ic]][[j]], R.mat = rot.mat, screen = 
NULL,
   #  distance = distance, add = TRUE, scale = FALSE, 
   #  light = c(.5,0,1), engine = grid)
 }
   }
 )
print(w)
 
dev.off()
 
 
From: Seth W Bigelow [mailto:sbige...@fs.fed.us] 
Sent: Tuesday, March 16, 2010 2:12 PM
To: Waichler, Scott R
Cc: r-help@r-project.org
Subject: Re: R-help Digest, Vol 85, Issue 16
 

Scott: 

This may work for you. Just include the statement 
par.settings - par.set1 in your wire graph statement 

par.set1 -list( 
axis.line=list(col=transparent), # Get 
rid of box around fig? 
clip=list(panel=FALSE),# 
disarm lurking panel settings? 
 
) 



Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California
sbige...@fs.fed.us /  ph. 530 759 1718

[[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.


Re: [R] conditioning variable in panel.xyplot?

2010-03-08 Thread Seth W Bigelow
Ah, wonderful, thank you for the code Deepayan. To recap for posterity: I 
have two datafiles, d and q: each has x-y coordinates that are conditioned 
by site (The actual data, for me, is maps of parent trees and their 
seedlings). I wanted to superimpose the xy plots of d and q, by site, 
without going to the trouble of merging the d  q datasets into a single 
dataset. The solution is to use the which.packet statement is 


d - data.frame(site  = c(rep(A,12), rep(B,12)), 
x=rnorm(24),y=rnorm(24))# Create the main xy dataset
q - data.frame(site  = c(rep(A,7), rep(B,7)), 
x=rnorm(14),y=rnorm(14))# Create the alternate xy dataset


q.split - split(q, q$site) # Split up the alternate 
dataset by site

mypanel - function(..., alt.data) {
with(alt.data[[ which.packet()[1] ]],   # 
which.packet passes index of the relevant data subset...
 panel.xyplot(x = x, y = y, col=red)) # ... to 
panel.xyplot()
panel.xyplot(...)
}

xyplot(y ~ x | site, d, alt.data = q.split, # After providing 
the alternative dataset and the panel...
   panel = mypanel) # ...everything prints out 
properly, like magic!



Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
[[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.


Re: [R] conditioning variable in panel.xyplot?

2010-03-05 Thread Seth W Bigelow
I'm stumped after an hour or so reading about subscripts in panel.xyplot. 
Apparently the panel function is executed for each subset of data in the 
main dataset (specified by the conditioning variable, 'site' in my 
example), and the 'subscripts' keyword passes a vector of the 
corresponding row numbers to the panel function. But, if I want the panel 
function to simultaneously plot data from a different dataframe, as in the 
example below, I don't understand how having a vector of row numbers from 
a subset of the dataframe used in the main xyplot statement helps me with 
selecting data from an entirely different dataframe ('q' in my example). 
 
library(lattice)

d - data.frame(site  = c(rep(A,12), rep(B,12)), 
x=rnorm(24),y=rnorm(24))
q - data.frame(site  = c(rep(A,7), rep(B,7)), 
x=rnorm(14),y=rnorm(14))

mypanel - function(...){
panel.xyplot(q$x, q$y, col=red)
panel.xyplot(...)}

xyplot(y ~ x | site, d,
panel = mypanel
)
 
--Seth


On Thu, Mar 4, 2010 at 4:42 PM, Seth W Bigelow sbige...@fs.fed.us wrote:
 I wish to create a multipanel plot (map) from several datasets (d and
 q in the example below). I can condition the main xyplot statement on
 the site variable, but I don't know how to pass a conditioning 
variable
 to panel.xyplot plot so that the x-y coordinates from dataset q are only
 plotted at the appropriate site.

The keyword is 'subscripts'. Look at the entry for 'panel' in ?xyplot,
and let us know if you still have doubts.

-Deepayan



 library(lattice)
 d - data.frame(site  = c(rep(A,12), rep(B,12)),
 x=rnorm(24),y=rnorm(24))# Create dataframe d,
 with 12 x-y coordinates for each site
 q - data.frame(site  = c(rep(A,7), rep(B,7)),
 x=rnorm(14),y=rnorm(14))# Create dataframe q,
 with 7 pairs of x-y coordinates for each site.

 mypanel - function(...){
panel.xyplot(q$x, q$y, col=red)   # Statement that
 needs a Site conditioning variable
panel.xyplot(...)}

 xyplot(y~x|site, d, panel=mypanel)  # Statement erroneously plots 
all
 14 x-y points in q on panels for sites A  B



 Dr. Seth  W. Bigelow
 Biologist, USDA-FS Pacific Southwest Research Station
 1731 Research Park Drive, Davis California
[[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.


[[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] conditioning variable in panel.xyplot?

2010-03-04 Thread Seth W Bigelow
I wish to create a multipanel plot (map) from several datasets (d and 
q in the example below). I can condition the main xyplot statement on 
the site variable, but I don't know how to pass a conditioning variable 
to panel.xyplot plot so that the x-y coordinates from dataset q are only 
plotted at the appropriate site.

 
library(lattice)
d - data.frame(site  = c(rep(A,12), rep(B,12)), 
x=rnorm(24),y=rnorm(24))# Create dataframe d, 
with 12 x-y coordinates for each site
q - data.frame(site  = c(rep(A,7), rep(B,7)), 
x=rnorm(14),y=rnorm(14))# Create dataframe q, 
with 7 pairs of x-y coordinates for each site.

mypanel - function(...){
panel.xyplot(q$x, q$y, col=red)   # Statement that 
needs a Site conditioning variable
panel.xyplot(...)}  

xyplot(y~x|site, d, panel=mypanel)  # Statement erroneously plots all 
14 x-y points in q on panels for sites A  B
 


Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California
[[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] subsetting by groups, with conditions

2009-12-28 Thread Seth W Bigelow
I have a data set similar to this:

P1idVeg1Veg2AreaPoly2   P2ID
1   p   p   1   1
1   p   p   1.5 2
2   p   p   2   3
2   p   h   3.5 4

For each group of Poly1id records, I wish to output (subset) the record 
which has largest AreaPoly2 value, but only if Veg1=Veg2. For this 
example, the desired dataset would be

P1idVeg1Veg2AreaPoly2   P2ID
1   p   p   1.5 2
2   p   p   2   3
 
Can anyone point me in the right direction on this?

Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California
[[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] xyplot: Can I identify groups but not use them for regression?

2009-09-18 Thread Seth W Bigelow
I wish to identify groups representing different treatments, but to plot 
them and do a regression using a continuous variable (cover) 
ignoring the groupings.

d$year - NA
d$year -c(rep(2007,12), rep(2008,12))
d$treatment - c(rep(A,4),rep(B,4),rep(C,4), rep(A,4), rep(B,4), 
rep(C,4))
d$cover - rnorm(24)
d$variable - rnorm(24)

xyplot(variable ~ cover | year, d, 
type=c(p,r),
groups=treatment
)

As it stands, a different regression line is plotted for each treatment.
Oh, and how do I display the actual numeric value of year (e.g., 2007) 
in the strip, rather than the word year?

--Seth



Dr. Seth  W. Bigelow
Biologist, USDA-FS Pacific Southwest Research Station
1731 Research Park Drive, Davis California
[[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] illegal levels in yaImpute() / AsciiGridImpute()

2009-05-05 Thread Seth W Bigelow
I'm using randomForest in yaImpute to create a yai-type object which 
associates L with landscape features. Then I use the sp() package to 
impute L to a landscape consisting of four ascii files) I keep getting the 
message NA's generated due to illegal level(s) when I do the imputation. 
It's probably because one of the landscape features (as, for 
aspect/slope) is stored in numeric form but is treated as a factor when 
the yai object is created. as is also stored in numeric form in the 
ascii grids, of course. I included an xtypes argument in the 
AsciiGridImpute statement, but that did 
not help. Some relevant statements are:

xfiles - list(DEM_10 = dem_10.asc, EASTING = easting.asc, 
NORTHING = northing.asc, as = asp_slop.asc)

AsciiGridImpute(yai_ob, xfiles, outfiles,
xtypes=list(numeric, numeric, integer, character))

Any insights will be appreciated. I'd particularly like to know how to 
gain access to the invisible list, VALUE, containing unexpectedNA's, 
illegal levels, and other information that would help me to troubleshoot 
the issue.

Dr. Seth  W. Bigelow
Biologist, USDA-FS Sierra Nevada Research Center
1731 Research Park Drive, Davis California
[[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] how do I eliminate excess levels in lattice contourplot key / legend?

2008-12-03 Thread Seth W Bigelow
I'm working on a contourplot( ) graph, the subject of several previous 
posts to this list. The contours express probabilities from 0 - 1, but the 
key that is automatically generated by contourplot pads the probability 
scale with values that are impossible (i.e, range goes from -0.2 to 1.2), 
which will be confusing to those who view the plot. How can I get the 
scale to just run from 0 - 1?

I have toiled mightily in the depths of the Murrell  Sarkar graphics 
books. Any pointers will be gratefully received.

--Seth

Minimal, commented code:

library(lattice)

model - function(a,b,c,d,e, f, X1,X2)  # model function for 
contour plot
{J - a + (b*X1) + (c*X2) + (d*X1*X2) + e*(X1^2) + f*(X2^2)
  pp - exp(J)/(1+exp(J))
  return(pp)}

g - expand.grid(X1= seq(0.3,0.9,0.01), X2 = seq(0.3,1, 0.01)) 
## create x and y data matrix

g$z - model(-29, -14, 52, 80, -3, -56, g$X1, g$X2) 
## Create variable z using model and g data frame

contourplot(z ~ X1 * X2,
data = g,
region = TRUE, # Add color to background
cuts = 5# Number of contour/color intervals. 
)


Dr. Seth  W. Bigelow
Sierra Nevada Research Center
USFS - PSW.
__
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 contourplot background covers inward-facing ticks

2008-11-24 Thread Seth W Bigelow
I wish to have inward-pointing ticks on my contourplot graph, but the 
colored background produced by the region=TRUE statement covers the 
ticks up, is there any way around this? Sample code below.  --Seth

library(lattice)

model - function(a,b,c,d,e, f, X1,X2)  # provide model function 
for contour plot
 {J - a + (b*X1) + (c*X2) + (d*X1*X2) + e*(X1^2) + f*(X2^2)
  pp - exp(J)/(1+exp(J))
  return(pp)}

g - expand.grid(X1= seq(0.3,0.9,0.001), X2 = seq(0.3,1, 0.001))
g$z - model(-29, -14, 52, 80, -3, -56, g$X1, g$X2) # Create 
variable z using gridded data, model, and variables

contourplot(z ~ X1 * X2, 
 data = g,
 region = TRUE, # Adds color to background
 cuts = 10, # Number of contour intervals...(and color 
intervals!)
 scales = list(tck = c(-1,-1))  # ticks go inward 
 )   ### END


[[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.


Re: [R] Coloring spaces between lines in xyplot

2008-09-23 Thread Seth W Bigelow

R-listers:

I am summarizing input I got on a recent query about creating stacked,
colored line plots in xyplot.
The only input I got regarding xyplot was to use the polygon() command, but
this seemed to require some awkward data manipulation.
In contrast, I got several snippets of functional code for use in the
ggplot2 and plotrix packages, both of which produced nice graphs with
minimal effort. (Apparently the filled bands option in the xYplot function
in the Hmisc package will also do this).

### stacked line graphs in plotrix package

x -matrix(x,nrow=10) # create matrix of x values
y -matrix(y,nrow=10) # create matrix of y values

stackpoly(x,y,stack=TRUE)   # make the graph


### stacked line graphs in ggplot2 package

x - rep(seq(1,10), 2)# create column of x values
y - c(1+1.5*(1:10), 0.2 + 1.3*(1:10) )   # create column of y values
trt - rep(c(low, high), each = 10)   # create column with identify of
treatments

qplot(x, y, fill=trt, geom=area)# plot the graph

I ended up using ggplot2, because I had to churn out a large number of
these, and the facets command allowed me to make panels
in a manner akin to the lattice system.

Thanks to Carl, Hadley, Xie, Jim and Frank for responding.

--Seth Bigelow



Dr. Seth  W. Bigelow
Biologist, Sierra Nevada Research Center
Pacific Southwest Research Station, USDA Forest Service. 1731 Research Park
Drive, Davis CA 95618

__
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] Coloring spaces between lines in xyplot

2008-09-19 Thread Seth W Bigelow

Ok, thanks to Carl Witthoft I now know that to color spaces between  and
below a pair of lines in xyplot, I will need to redefine the lines as
polygons, and use the lpolygon panel function, as in the following

library(lattice)
p - c(1,10,10,1)   #  vector of x values
q - c(4,29.2,16,2.5)  # vector of y values for upper polygon
r - c(2.5,16,0,0)# vector of y values for lower
polygon

xyplot(
  q + r ~ p,
  panel = lpolygon,
  col = c(red,green)
  )

But, having spent several hours arriving at this increment of knowlege, I
find myself stumped at how to assign different colors to the two polygons!
the above col line did not do the job.

--Seth



Dr. Seth  W. Bigelow
Biologist, Sierra Nevada Research Center
Pacific Southwest Research Station, USDA Forest Service. 1731 Research Park
Drive, Davis CA 95618
[EMAIL PROTECTED]
www.fs.fed.us/psw/programs/snrc/staff/bigelow
www.swbigelow.net

Phone: 530 759 1718
Fax: 530 747 0241

__
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] Coloring spaces between lines in xyplot

2008-09-18 Thread Seth W Bigelow

Greetings:
 I wish to create a stacked line graph in xyplot, adding color to the
spaces between the lines. For example, the code below creates a plot with
two lines extending across it, and I want to color the rhomboid that is
between the upper and lower line, and between the lower line and the bottom
of the frame.
Suggestions appreciated

--Seth Bigelow

library(lattice)
x=seq(1,10)   #define independent variable
lo = 1+1.5*x  #create lower line
hi = lo + (0.2 + 1.3*x)# create upper line, add it to lower

xyplot(
  lo+hi~x,
  type=l,
  main = Stacked Line plot,
  xlim=c(1,10))

__
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] Overlaying trellis xyplot on contourplot

2007-12-13 Thread Seth W Bigelow

Friends: I wish to overlay data points on a contour graph.  The following
example produces a nice contour plot, but I have not mastered the concept
of using panel functions to modify plots. Can someone show me how to
overlay the data points (given after contour plot statement) on the
contourplot?
--Seth


model - function(a,b,c,X1,X2)# provide model
function for contour plot
 {(exp(a + b*X1 + c*X2)) / (1 + exp(a + b*X1 + c*X2))}

g - expand.grid(X1 = seq(0.40, 0.8,0.01), X2 = seq(0.03,0.99,0.03)) #
create gridded data for contour plot
a - -37.61   # Assign value to 'a' parameter
b - 34.88# Assign value to 'b' parameter
c - 28.44# Assign value to 'c' parameter
g$z- model(a, b, c, g$X1,g$X2)   # Create variable z
using gridded data, model, and variables

contourplot(z ~ X1 * X2,  # specify the basic
equation for the contour plot
 data=g,  # Specify the data frame to be
used
 contour=TRUE,  # Make sure it adds
contours
 xlim=c(0.4,0.8), ylim=c(0.401,0.999), zlim=c(0,1), # Set axis
ranges
 xlab=p(H), ylab=p(H|H),# Add axis labels
 region = TRUE, # Add nice colors
 cuts=10  # Specify number of contour
slices
 )

# Data to superimpose as xyplot on the contourplot

ph -c(0.42,0.47,0.59,0.40) # Create a vector of values
under variable 'ph'
phh -c(0.76,0.81,0.82,0.71)  # Create vector of
values for variable 'phh'
d - data.frame(ph,phh)   # Group variables ph
 phh in data frame 'd'




Dr. Seth  W. Bigelow
Biologist, Sierra Nevada Research Center
Pacific Southwest Research Station, USDA Forest Service
Mailing address: 2121 2nd St Suite A101, Davis CA 95616
www.fs.fed.us/psw/programs/snrc/staff/bigelow
www.smbigelow.net
Phone: 530 759 1718
Fax: 530 747 0241

__
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] Overlaying trellis xyplot on contourplot

2007-12-13 Thread Seth W Bigelow
Deepayan:

 Very nice, thanks for introducing me to a new resource. I will include the
entire, functioning example in the event others may find it useful.

--Seth

## Sample code for overlaying data points on a contour graph, using
xyplot and contourplot ##

library(lattice)

model - function(a,b,c,X1,X2)# provide model function for
contour plot
 {(exp(a + b*X1 + c*X2)) / (1 + exp(a + b*X1 + c*X2))}

g - expand.grid(X1 = seq(0.38, 0.8,0.01), X2 = seq(0.03,0.99,0.03)) #
create gridded data for contour plot
a - -37.61   # Assign value to 'a' parameter
b - 34.88# Assign value to 'b' parameter
c - 28.44# Assign value to 'c' parameter
g$z- model(a, b, c, g$X1,g$X2)   # Create variable z using gridded
data, model, and variables

# Data to superimpose as xyplot on the contourplot
ph -c(0.42,0.47,0.59,0.40)   # Create a vector of values under
variable 'ph'
phh -c(0.76,0.81,0.82,0.71)  # Create vector of values for
variable 'phh'
d - data.frame(ph,phh)   # Group variables ph  phh in
data frame 'd'

contourplot(z ~ X1 * X2,
 data=g,
 contour=TRUE,
 xlim=c(0.38,0.8), ylim=c(0.401,0.999), zlim=c(0,1), # Set Axis Ranges
 xlab=p(H), ylab=p(H|H),  # Set axis labels
 region = TRUE,
 cuts=10,
 panel = function(x,y,subscripts,...){
 panel.contourplot(x,y,subscripts,...)
 panel.xyplot(d$ph,d$phh)}
 )

 End ##

__
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.