Re: [R] shading in overlap between two ranges

2011-06-06 Thread Graves, Gregory
This worked perfectly.  An example graphic is located here:
ftp://ftp.sfwmd.gov/pub/ggraves/ribbon.bmp


-Original Message-
From: Dennis Murphy [mailto:djmu...@gmail.com] 
Sent: Thursday, June 02, 2011 12:11 PM
To: Graves, Gregory
Cc: r-help@r-project.org; Kemp, Susan K SAJ; patrick_pi...@fws.gov
Subject: Re: [R] shading in overlap between two ranges

Hi:

Here's one approach using geom_ribbon() in ggplot2 - the 'overlap' is
the change in color where the two ribbons intersect. Using your
example data with the same names and the 'one.month' variable removed,

library(ggplot2)
ggplot() +
  geom_ribbon(data = target, aes(x = i.value, ymin = X25, ymax = X75,
 fill = 'Target'), alpha = 0.4) +
  geom_ribbon(data = observed, aes(x = i.value, ymin = X25, ymax = X75,
 fill = 'Observed'), alpha = 0.4) +
  scale_fill_manual(, c('Target' = 'blue', 'Observed' = 'orange')) +
  opts(legend.position = c(0.88, 0.85),
   legend.background = theme_rect(colour = 'transparent'),
   legend.text = theme_text(size = 12)) +
  labs(x = 'Month', y = 'Value')

There is a separate geom_ribbon() for each of target and observed. A
factor variable for fill color is generated on the fly with colors
specified in scale_fill_manual(). The opts() reposition the legend
inside the graphics region (the values represent proportions of the
total graphics area in each direction), make the legend background
transparent and slightly increase the size of the legend labels
(default size = 10 in theme_text).
Alpha transparency is used so that the overlap creates a blend of the
two colors; without it, one overwrites the other.

HTH,
Dennis


On Thu, Jun 2, 2011 at 8:04 AM, Graves, Gregory ggra...@sfwmd.gov wrote:
 I have 2 datafiles 'target' and 'observed' as shown below (I will gladly
 email these 2 small files to whomever).  X25. And X75. Indicate the
 value of 25th and 75th-percentile of the target ('what should be') and
 the observed ('what is').  The i.value is simply the month.

 target
        X        i.value    X25.     X75.
 1  one.month       1 10.845225 17.87237
 2  one.month       2 12.235813 19.74490
 3  one.month       3 14.611749 23.44810
 4  one.month       4 17.529332 28.09647
 5  one.month       5 19.458738 30.56936
 6  one.month       6 15.264505 28.29333
 7  one.month       7 12.370369 23.35455
 8  one.month       8 12.471224 21.82794
 9  one.month       9  9.716685 17.28762
 10 one.month      10  6.470568 12.49830
 11 one.month      11  6.180560 14.24961
 12 one.month      12  9.673738 15.79208

 observed
     X         i.value   X25.     X75.
 1  one.month       1 19.81000 27.63500
 2  one.month       2 23.64062 30.09125
 3  one.month       3 26.04865 35.99104
 4  one.month       4 32.02625 41.50958
 5  one.month       5 34.74479 47.75958
 6  one.month       6 37.48885 46.56448
 7  one.month       7 30.06740 40.10146
 8  one.month       8 26.14917 39.49458
 9  one.month       9 14.12521 32.39406
 10 one.month      10 11.04125 23.55479
 11 one.month      11 13.14917 23.56833
 12 one.month      12 17.17938 27.02458

 The following plots 4 lines on one graph.  The area between the two red
 lines represents the target 'zone', and the area between the two black
 lines is the observed 'zone'.

 with(target, plot(X25.~i.value,ylim=c(0,55),type='l',col='red'))
 par(new=T)
 with(target, plot(X75.~i.value,ylim=c(0,55),type='l',col='red'))
 par(new=T)
 with(observed, plot(X25.~i.value,ylim=c(0,55),type='l'))
 par(new=T)
 with(observed, plot(X75.~i.value,ylim=c(0,55),type='l'))
 par(new=F)

 Ideally, the target and the observed should overlap in every month -
 they don't.  The desire is to visually accentuate the amount of overlap
 by shading in the area where these two zones overlap.  How would you
 do that?  Note, that in some of these characterizations, the overlap
 wanders in and out [I already have routines that calculate the percent
 of overlap, but I have been requested to find a way to shade the
 overlap.]

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


[R] shading in overlap between two ranges

2011-06-02 Thread Graves, Gregory
I have 2 datafiles 'target' and 'observed' as shown below (I will gladly
email these 2 small files to whomever).  X25. And X75. Indicate the
value of 25th and 75th-percentile of the target ('what should be') and
the observed ('what is').  The i.value is simply the month.  

 target
Xi.valueX25. X75.
1  one.month   1 10.845225 17.87237
2  one.month   2 12.235813 19.74490
3  one.month   3 14.611749 23.44810
4  one.month   4 17.529332 28.09647
5  one.month   5 19.458738 30.56936
6  one.month   6 15.264505 28.29333
7  one.month   7 12.370369 23.35455
8  one.month   8 12.471224 21.82794
9  one.month   9  9.716685 17.28762
10 one.month  10  6.470568 12.49830
11 one.month  11  6.180560 14.24961
12 one.month  12  9.673738 15.79208

 observed
 X i.value   X25. X75.
1  one.month   1 19.81000 27.63500
2  one.month   2 23.64062 30.09125
3  one.month   3 26.04865 35.99104
4  one.month   4 32.02625 41.50958
5  one.month   5 34.74479 47.75958
6  one.month   6 37.48885 46.56448
7  one.month   7 30.06740 40.10146
8  one.month   8 26.14917 39.49458
9  one.month   9 14.12521 32.39406
10 one.month  10 11.04125 23.55479
11 one.month  11 13.14917 23.56833
12 one.month  12 17.17938 27.02458

The following plots 4 lines on one graph.  The area between the two red
lines represents the target 'zone', and the area between the two black
lines is the observed 'zone'.

with(target, plot(X25.~i.value,ylim=c(0,55),type='l',col='red'))
par(new=T)   
with(target, plot(X75.~i.value,ylim=c(0,55),type='l',col='red'))
par(new=T) 
with(observed, plot(X25.~i.value,ylim=c(0,55),type='l'))
par(new=T) 
with(observed, plot(X75.~i.value,ylim=c(0,55),type='l'))
par(new=F)

Ideally, the target and the observed should overlap in every month -
they don't.  The desire is to visually accentuate the amount of overlap
by shading in the area where these two zones overlap.  How would you
do that?  Note, that in some of these characterizations, the overlap
wanders in and out [I already have routines that calculate the percent
of overlap, but I have been requested to find a way to shade the
overlap.]

__
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 to eliminate first row in datafile created in do loop

2011-05-24 Thread Graves, Gregory
I am trying to create a routine that would take a time series and
generate monthly 25%tile and 75%tile limits based on 12 calendar months.
I have succeeded to create a do loop to do this, but can't figure out
how to initiate the receiving datafile (in this case limit.list)
without sticking an initial set of zeroes in.  I'd like to be able to
insert a new column i.value for each time i increments 1 thru 12, to
represent the 12 months, but I can't figure out how to join the value of
i to the lower and upper variables.  Close but no cigar here.

lower=0
upper=0
limit.list-data.frame(lower,upper)
for(i in 1:12){
s=subset(paleo,month==i);
one.month=with(s, quantile(WBpaleo, c(.25, .75), na.rm=T));
limit.list-rbind(limit.list,one.month)  
}
limit.list

which gives me this:
 limit.list
  lowerupper
1   0.0  0.0
2  25.51786 29.68823
3  26.09828 30.92770
4  27.75703 33.04016
5  29.53395 36.14273
6  30.89420 37.65727
7  29.27843 37.59690
8  27.50141 34.36265
9  26.40554 32.88533
10 25.13494 29.83829
11 23.48982 27.14612
12 22.88814 27.52782
13 24.51789 28.24871

How do I avoid having row 1 in my list?

I can delete the first row with:
limit.list = limit.list[-1,]

but that messes up my month variable

 limit.list
  lowerupper
2  25.51786 29.68823
3  26.09828 30.92770
4  27.75703 33.04016
5  29.53395 36.14273
6  30.89420 37.65727
7  29.27843 37.59690
8  27.50141 34.36265
9  26.40554 32.88533
10 25.13494 29.83829
11 23.48982 27.14612
12 22.88814 27.52782
13 24.51789 28.24871

__
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] how to eliminate first row in datafile created in do loop

2011-05-24 Thread Graves, Gregory
Certainly closer, and I can get by with this ... but ... would like to
not have the one.months .

limit.list-NULL
for(i in 1:12){
s=subset(paleo,month==i);
one.month=with(s, quantile(WBpaleo, c(.25, .75), na.rm=T));
one.month=c(as.character(i),one.month);
limit.list-rbind(limit.list,one.month)  
}

 limit.list
   25% 75%
one.month 1  25.51786389   29.68823492  
one.month 2  26.09827974   30.9276985   
one.month 3  27.757034405  33.040163045 
one.month 4  29.53395155   36.1427293975
one.month 5  30.894195075  37.657271835 
one.month 6  29.27843098   37.59689852  
one.month 7  27.5014142975 34.36265367  
one.month 8  26.405542532.88533117  
one.month 9  25.1349430375 29.838291435 
one.month 10 23.48982439   27.14611846  
one.month 11 22.88814497   27.52782293  
one.month 12 24.5178851225 28.248711925


-Original Message-
From: Ian Gow [mailto:iand...@gmail.com] 
Sent: Tuesday, May 24, 2011 8:58 AM
To: Graves, Gregory; Nungesser, Martha; r-help@r-project.org
Cc: Kemp, Susan K SAJ; patrick_pi...@fws.gov
Subject: Re: [R] how to eliminate first row in datafile created in do
loop

Gregory: Would setting limit.list - NULL at the start do the trick? See
example below:

Analogue of your example:

lower - 0
upper - 0
limit.list-data.frame(lower,upper)
for(i in 1:12) {
some.data - rnorm(2)
   lower - min(some.data)
  upper - max(some.data)
  one.month - data.frame(lower, upper)
  limit.list - rbind(limit.list, one.month)
}
limit.list

Approach that doesn't give zeroes at the start:

limit.list - NULL
for(i in 1:12) {
some.data - rnorm(2)
  lower - min(some.data)
  upper - max(some.data)
  one.month - data.frame(lower, upper)
  limit.list - rbind(limit.list, one.month)
}
limit.list


-Ian

On 5/24/11 7:30 AM, Graves, Gregory ggra...@sfwmd.gov wrote:

I am trying to create a routine that would take a time series and
generate monthly 25%tile and 75%tile limits based on 12 calendar
months.
I have succeeded to create a do loop to do this, but can't figure out
how to initiate the receiving datafile (in this case limit.list)
without sticking an initial set of zeroes in.  I'd like to be able to
insert a new column i.value for each time i increments 1 thru 12,
to
represent the 12 months, but I can't figure out how to join the value
of
i to the lower and upper variables.  Close but no cigar here.

lower=0
upper=0
limit.list-data.frame(lower,upper)
for(i in 1:12){
   s=subset(paleo,month==i);
one.month=with(s, quantile(WBpaleo, c(.25, .75), na.rm=T));
limit.list-rbind(limit.list,one.month)
}
limit.list

which gives me this:
 limit.list
  lowerupper
1   0.0  0.0
2  25.51786 29.68823
3  26.09828 30.92770
4  27.75703 33.04016
5  29.53395 36.14273
6  30.89420 37.65727
7  29.27843 37.59690
8  27.50141 34.36265
9  26.40554 32.88533
10 25.13494 29.83829
11 23.48982 27.14612
12 22.88814 27.52782
13 24.51789 28.24871

How do I avoid having row 1 in my list?

I can delete the first row with:
limit.list = limit.list[-1,]

but that messes up my month variable

 limit.list
  lowerupper
2  25.51786 29.68823
3  26.09828 30.92770
4  27.75703 33.04016
5  29.53395 36.14273
6  30.89420 37.65727
7  29.27843 37.59690
8  27.50141 34.36265
9  26.40554 32.88533
10 25.13494 29.83829
11 23.48982 27.14612
12 22.88814 27.52782
13 24.51789 28.24871

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


Re: [R] tapply output as a dataframe

2011-02-03 Thread Graves, Gregory
On Mon, Apr 13, 2009 at 12:41 PM, Dan Dube ddube-at-advisen.com wrote:

 i use tapply and by often, but i always end up banging my head against
 the wall with the output.

The proposed solution of Dan's problem posted on R-help was: 

 do.call(rbind,a)

When I use this 'solution' I get 'ERROR:  second argument must be a list'.  So 
head on wall continues.

My tapply output is generated as follows:

 a=tapply(value,list(sampling.date,station.code),mean)

which gives me this (in part):

 A B C D E F G H I J  K
1/15/2008  0.004 0.027 0.019 0.015 0.035 0.022 0.007 0.038 0.042 0.045 0.0350
1/15/2009  0.027 0.027 0.031 0.015 0.008 0.021 0.007 0.027 0.026 0.029 0.0210
1/15/2010  0.016 0.020 0.015 0.022 0.015 0.013 0.007 0.014 0.019 0.019 0.0180
10/15/2007 0.052 0.051 0.032 0.024 0.017 0.044 0.015 0.058 0.063 0.061 0.0640
10/15/2008 0.042 0.054 0.030 0.017 0.024 0.030 0.019 0.044 0.047 0.051 0.0390
10/15/2009 0.047 0.035 0.031 0.020 0.012 0.039 0.019 0.051 0.055 0.054 0.0350

The only way I can figure out how to resolve this, such that I can, for 
example, plot station A against date, is to export the tapply output as a 
csv, and then reimport.

Suggestions?  I couldn't find a solution to this likely SIMPLE problem in 
Crawley or multiple searches of R help.

Gregory A. Graves, Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Wetland Watershed Sciences / Restoration Sciences Department
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
       CELL:  561 / 719 - 8157

__
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] tapply output as a dataframe

2011-02-03 Thread Graves, Gregory
Yes, as far as I can tell, sampling.date is a character vector of the format 
1/15/2008.  It resides in the leftmost column of the tapply output.

station.code are the A, B, C column headers which refer actual water quality 
station locations, and the values below those headers correspond to the 
sampling.date when samples were taken.  Actually what I have done is to take 
the mid-point of each month and calculated its mean to deal with multiple 
samples taken in one month, and to generate NAs where no sample was taken by 
purposefully not adding the na.rm=T to the tapply command.

Normally I would do this:
 rdate-as.POSIXct(strptime(date,format=%m/%d/%Y)) #convert sampling.date to 
 date R can handle
 plot(A~rdate)

If I just submit station.code like
 A
I get all the values for Station A.

It is in converting the sampling.date to an rdate that has me stumped.  One 
reason being that in the tapply output the character vector representing date 
has no column name.  I can't access that column.

Gregory A. Graves, Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Wetland Watershed Sciences / Restoration Sciences Department
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
       CELL:  561 / 719 - 8157


-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Thursday, February 03, 2011 12:50 PM
To: Graves, Gregory
Cc: r-help@r-project.org; Goodman, Patricia; Gorman, Patricia
Subject: Re: [R] tapply output as a dataframe


On Feb 3, 2011, at 11:29 AM, Graves, Gregory wrote:


 My tapply output is generated as follows:

 a=tapply(value,list(sampling.date,station.code),mean)

Why not give us sampling.date (which is probably NOT really a date but  
rather a character vector) and station.code so we can show you how to  
create a more appropriate structure?


 which gives me this (in part):

 A B C D E F G H I  
 J  K
 1/15/2008  0.004 0.027 0.019 0.015 0.035 0.022 0.007 0.038 0.042  
 0.045 0.0350
 1/15/2009  0.027 0.027 0.031 0.015 0.008 0.021 0.007 0.027 0.026  
 0.029 0.0210
 1/15/2010  0.016 0.020 0.015 0.022 0.015 0.013 0.007 0.014 0.019  
 0.019 0.0180
 10/15/2007 0.052 0.051 0.032 0.024 0.017 0.044 0.015 0.058 0.063  
 0.061 0.0640
 10/15/2008 0.042 0.054 0.030 0.017 0.024 0.030 0.019 0.044 0.047  
 0.051 0.0390
 10/15/2009 0.047 0.035 0.031 0.020 0.012 0.039 0.019 0.051 0.055  
 0.054 0.0350

 The only way I can figure out how to resolve this, such that I can,  
 for example, plot station A against date, is to export the tapply  
 output as a csv, and then reimport.


 Suggestions?  I couldn't find a solution to this likely SIMPLE problem

Perhaps. but we haven't really been told what the problem is, have we?

 in Crawley or multiple searches of R help.


 Gregory A. Graves, Lead Scientist


David Winsemius, MD
West Hartford, CT

__
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] tapply output as a dataframe

2011-02-03 Thread Graves, Gregory
This works.  Thanks.

Gregory A. Graves, Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Wetland Watershed Sciences / Restoration Sciences Department
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
       CELL:  561 / 719 - 8157


-Original Message-
From: Phil Spector [mailto:spec...@stat.berkeley.edu] 
Sent: Thursday, February 03, 2011 12:41 PM
To: Graves, Gregory
Cc: r-help@r-project.org; Goodman, Patricia; Gorman, Patricia
Subject: Re: [R] tapply output as a dataframe

Try
   as.data.frame(as.table(a))

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Thu, 3 Feb 2011, Graves, Gregory wrote:

 On Mon, Apr 13, 2009 at 12:41 PM, Dan Dube ddube-at-advisen.com wrote:

 i use tapply and by often, but i always end up banging my head against
 the wall with the output.

 The proposed solution of Dan's problem posted on R-help was:

 do.call(rbind,a)

 When I use this 'solution' I get 'ERROR:  second argument must be a list'.  
 So head on wall continues.

 My tapply output is generated as follows:

 a=tapply(value,list(sampling.date,station.code),mean)

 which gives me this (in part):

 A B C D E F G H I J  K
 1/15/2008  0.004 0.027 0.019 0.015 0.035 0.022 0.007 0.038 0.042 0.045 0.0350
 1/15/2009  0.027 0.027 0.031 0.015 0.008 0.021 0.007 0.027 0.026 0.029 0.0210
 1/15/2010  0.016 0.020 0.015 0.022 0.015 0.013 0.007 0.014 0.019 0.019 0.0180
 10/15/2007 0.052 0.051 0.032 0.024 0.017 0.044 0.015 0.058 0.063 0.061 0.0640
 10/15/2008 0.042 0.054 0.030 0.017 0.024 0.030 0.019 0.044 0.047 0.051 0.0390
 10/15/2009 0.047 0.035 0.031 0.020 0.012 0.039 0.019 0.051 0.055 0.054 0.0350

 The only way I can figure out how to resolve this, such that I can, for 
 example, plot station A against date, is to export the tapply output as a 
 csv, and then reimport.

 Suggestions?  I couldn't find a solution to this likely SIMPLE problem in 
 Crawley or multiple searches of R help.

 Gregory A. Graves, Lead Scientist
 Everglades REstoration COoordination and VERification (RECOVER)
 Wetland Watershed Sciences / Restoration Sciences Department
 South Florida Water Management District
 Phones:  DESK: 561 / 682 - 2429
        CELL:  561 / 719 - 8157

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


Re: [R] reference text variables as column name to plot [SOLVED]

2010-12-01 Thread Graves, Gregory
The following works nicely.  Thank you.

plot(z, sf[[s]], type=l)  #where the dataframe name in my case is sf

Sorry - I meant to say there were 24 rows in each column, so z=1:24

Gregory A. Graves, Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Restoration Sciences Department
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
       CELL:  561 / 719 - 8157


-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Tuesday, November 30, 2010 11:50 AM
To: Graves, Gregory
Cc: r-help@r-project.org
Subject: Re: [R] reference text variables as column name to plot


On Nov 30, 2010, at 11:40 AM, Graves, Gregory wrote:

 Having given myself carpal tunnel looking for answer to this ...



 I have a dataset

Named what?

 each column of which has 12 rows in it.  I created a
 variable 'z' as follows:



 z=1:24  s


Why did you put twice as many elements in z as there are in a column?




 Since I have a large number of these plots to make, and they are a bit
 complex, I want to want to reference the column I want to plot via a
 variable containing the name of that column.  As follows:



 similar='1978'

 s=paste('Y',similar,sep='')



 variable s now contains 'Y1978' which is the name of one of the  
 columns.



 However, when I try to plot



 plot(z,s,type='l')

Try this ... assuming that there really are 12 item length columns in  
a dataframe named, dfm.

plot(1:12, dfm[[s]], type=l)

dataframes are lists that can be accessed by the names of columns  
which are interpreted. Don't assume that you can get such  
interpretation with the $ operator.



 I get a 'x and y lengths differ' error because variable s is being
 recognized as 'Y1978' length=1, rather than the contents of the column
 Y1978 length=12.

 I tried all the usual tricks I know like s.

Huh?  is a logical operator.

  How do you get R to
 reference a variable as a column name?



 Thank you.



 Gregory A. Graves, Lead Scientist

 Everglades REstoration COoordination and VERification (RECOVER)

 Restoration Sciences Department

 South Florida Water Management District

 Phones:  DESK: 561 / 682 - 2429

   CELL:  561 / 719 - 8157




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

David Winsemius, MD
West Hartford, CT

__
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] reference text variables as column name to plot

2010-11-30 Thread Graves, Gregory
Having given myself carpal tunnel looking for answer to this ...

 

I have a dataset each column of which has 12 rows in it.  I created a
variable 'z' as follows:

 

z=1:24  

 

Since I have a large number of these plots to make, and they are a bit
complex, I want to want to reference the column I want to plot via a
variable containing the name of that column.  As follows:

 

similar='1978'

s=paste('Y',similar,sep='')

 

variable s now contains 'Y1978' which is the name of one of the columns.

 

However, when I try to plot

 

plot(z,s,type='l')

 

I get a 'x and y lengths differ' error because variable s is being
recognized as 'Y1978' length=1, rather than the contents of the column
Y1978 length=12.

 

I tried all the usual tricks I know like s.  How do you get R to
reference a variable as a column name?

 

Thank you.

 

Gregory A. Graves, Lead Scientist

Everglades REstoration COoordination and VERification (RECOVER) 

Restoration Sciences Department

South Florida Water Management District

Phones:  DESK: 561 / 682 - 2429 

   CELL:  561 / 719 - 8157

 


[[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] stacking consecutive columns

2010-11-17 Thread Graves, Gregory
I have a file, each column of which is a separate year, and each row of each 
column is mean precipitation for that month.  Looks like this (except it goes 
back to 1964).

monthX2000  X2001  X2002  X2003  X2004  X2005  X2006 X2007  X2008  
X2009 
11.600  1.010  4.320  2.110  0.925  3.275  3.460 0.675  1.315  2.920
22.960  3.905  3.230  2.380  2.720  1.880  2.430 1.380  2.480  2.380
31.240  1.815  1.755  1.785  1.250  3.940 10.025 0.420  2.845  2.460
43.775  1.350  2.745  0.170  0.710  2.570  0.255 0.425  4.470  1.250
54.050  1.385  5.650  1.515 12.005  6.895  7.020 4.060  7.725  2.775
68.635  8.900 15.715 12.680 16.270 12.605  7.095 7.025 10.465  7.345
75.475  7.955  7.880  6.670  7.955  7.355  5.475 5.650  7.255  7.985
88.435  5.525  7.120  6.250  7.150  7.610  5.525 6.500  6.275 10.405
95.855  7.830  7.250  7.355  9.715  7.850  6.385 7.960  4.485  7.250
10  7.965 11.915  6.735  8.125  7.855 10.465  4.340 6.165  2.400  3.240
11  1.705  1.525  0.905  1.670  1.840  2.100  0.255 2.830  4.425  1.645
12  2.335  0.840  0.795  1.890  0.145  1.700  0.260 2.160  2.300  2.220

What I want to do is to stack 2008 data underneath 2009 data, 2007 under 2008, 
2006 under 2007, etc.  I have so far figured out that I can do this with the 
following clumsy approach:

a=stack(yearmonth,select=c(X2009,X2008))
b=stack(yearmonth,select=c(X2008,X2007))
x=as.data.frame(c(a,b))
write.table(x,clipboard,sep= ,col.names=NA) #then paste this back into 
Excel to get this


values  ind values.1ind.1
1   0.275   X2009   1.285   X2008
2   0.41X2009   3.85X2008
3   1.915   X2009   3.995   X2008
4   1.25X2009   3.845   X2008
5   8.76X2009   2.095   X2008
6   8.65X2009   8.29X2008
7   7.175   X2009   9.405   X2008
8   7.19X2009   13.44   X2008
9   8.13X2009   7.245   X2008
10  1.46X2009   5.645   X2008
11  2.56X2009   0.535   X2008
12  5.01X2009   1.225   X2008
13  1.285   X2008   0.72X2007
14  3.85X2008   1.89X2007
15  3.995   X2008   1.035   X2007
16  3.845   X2008   2.86X2007
17  2.095   X2008   3.785   X2007
18  8.29X2008   9.62X2007
19  9.405   X2008   9.245   X2007
20  13.44   X2008   5.595   X2007
21  7.245   X2008   8.4 X2007
22  5.645   X2008   6.705   X2007
23  0.535   X2008   1.47X2007
24  1.225   X2008   1.665   X2007


Is there an easier, cleaner way to do this?  Thanks.

Gregory A. Graves, Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Restoration Sciences Department
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
       CELL:  561 / 719 - 8157

__
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] stacking consecutive columns

2010-11-17 Thread Graves, Gregory
Elegant or not ... This approach worked as intended, the objective being to 
create individual 'years' each of which was 24 months long (not 12) such that 
each 'year' reflected the antecedent rainfall condition.  THANKS.

I needed to do this to help us identify years that were similar to one another 
with respect to resultant water-level stage pattern in the Everglades.  Thus 
the need to examine each year in respect to its preceeding year.

Gregory A. Graves, Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Restoration Sciences Department
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
       CELL:  561 / 719 - 8157


-Original Message-
From: Patrick Hausmann [mailto:patrick.hausm...@uni-bremen.de] 
Sent: Wednesday, November 17, 2010 9:49 AM
To: r-help@r-project.org; Graves, Gregory
Subject: Re: [R] stacking consecutive columns


Hi Gregory,

is this what you want? Ok, not the most elegant way...

# using 'melt' from the 'reshape' package

library(reshape)
Data - data.frame(month = 1:12,
  x2002 = runif(12),
  x2003 = runif(12),
  x2004 = runif(12),
  x2005 = runif(12))

v - NULL

for(i in 2:4) {
  kk - melt(Data[, c(1, i, i+1)], id.vars=month, variable_name=year)
  v[[i-1]] - kk[order(kk$year, decreasing=TRUE),]
}

out - do.call(cbind, v)

HTH
Patrick

Am 17.11.2010 15:03, schrieb Graves, Gregory:
 I have a file, each column of which is a separate year, and each row of each 
 column is mean precipitation for that month.  Looks like this (except it goes 
 back to 1964).

 monthX2000  X2001  X2002  X2003  X2004  X2005  X2006 X2007  X2008  
 X2009
 11.600  1.010  4.320  2.110  0.925  3.275  3.460 0.675  1.315  
 2.920
 22.960  3.905  3.230  2.380  2.720  1.880  2.430 1.380  2.480  
 2.380
 31.240  1.815  1.755  1.785  1.250  3.940 10.025 0.420  2.845  
 2.460
 43.775  1.350  2.745  0.170  0.710  2.570  0.255 0.425  4.470  
 1.250
 54.050  1.385  5.650  1.515 12.005  6.895  7.020 4.060  7.725  
 2.775
 68.635  8.900 15.715 12.680 16.270 12.605  7.095 7.025 10.465  
 7.345
 75.475  7.955  7.880  6.670  7.955  7.355  5.475 5.650  7.255  
 7.985
 88.435  5.525  7.120  6.250  7.150  7.610  5.525 6.500  6.275 
 10.405
 95.855  7.830  7.250  7.355  9.715  7.850  6.385 7.960  4.485  
 7.250
 10  7.965 11.915  6.735  8.125  7.855 10.465  4.340 6.165  2.400  
 3.240
 11  1.705  1.525  0.905  1.670  1.840  2.100  0.255 2.830  4.425  
 1.645
 12  2.335  0.840  0.795  1.890  0.145  1.700  0.260 2.160  2.300  
 2.220

 What I want to do is to stack 2008 data underneath 2009 data, 2007 under 
 2008, 2006 under 2007, etc.  I have so far figured out that I can do this 
 with the following clumsy approach:

 a=stack(yearmonth,select=c(X2009,X2008))
 b=stack(yearmonth,select=c(X2008,X2007))
 x=as.data.frame(c(a,b))
 write.table(x,clipboard,sep=   ,col.names=NA) #then paste this back 
 into Excel to get this


   values  ind values.1ind.1
 1 0.275   X2009   1.285   X2008
 2 0.41X2009   3.85X2008
 3 1.915   X2009   3.995   X2008
 4 1.25X2009   3.845   X2008
 5 8.76X2009   2.095   X2008
 6 8.65X2009   8.29X2008
 7 7.175   X2009   9.405   X2008
 8 7.19X2009   13.44   X2008
 9 8.13X2009   7.245   X2008
 101.46X2009   5.645   X2008
 112.56X2009   0.535   X2008
 125.01X2009   1.225   X2008
 131.285   X2008   0.72X2007
 143.85X2008   1.89X2007
 153.995   X2008   1.035   X2007
 163.845   X2008   2.86X2007
 172.095   X2008   3.785   X2007
 188.29X2008   9.62X2007
 199.405   X2008   9.245   X2007
 2013.44   X2008   5.595   X2007
 217.245   X2008   8.4 X2007
 225.645   X2008   6.705   X2007
 230.535   X2008   1.47X2007
 241.225   X2008   1.665   X2007


 Is there an easier, cleaner way to do this?  Thanks.

 Gregory A. Graves, Lead Scientist
 Everglades REstoration COoordination and VERification (RECOVER)
 Restoration Sciences Department
 South Florida Water Management District
 Phones:  DESK: 561 / 682 - 2429
 CELL:  561 / 719 - 8157

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


Re: [R] stacking consecutive columns

2010-11-17 Thread Graves, Gregory
Follows is the exact solution to this:

v - NULL

#note that decreasing is FALSE so preceding year preceeds

for(i in 2:46) {
  kk - melt(yearmonth[, c(1, i, i+1)], id.vars=month, variable_name=year)
  v[[i-1]] - kk[order(kk$year, decreasing=FALSE),]
}

x - do.call(cbind, v)
write.table(x,clipboard,sep= ,col.names=NA)  #export to Excell via Ctrl-V


Gregory A. Graves, Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Restoration Sciences Department
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
       CELL:  561 / 719 - 8157


-Original Message-
From: Patrick Hausmann [mailto:patrick.hausm...@uni-bremen.de] 
Sent: Wednesday, November 17, 2010 9:49 AM
To: r-help@r-project.org; Graves, Gregory
Subject: Re: [R] stacking consecutive columns


Hi Gregory,

is this what you want? Ok, not the most elegant way...

# using 'melt' from the 'reshape' package

library(reshape)
Data - data.frame(month = 1:12,
  x2002 = runif(12),
  x2003 = runif(12),
  x2004 = runif(12),
  x2005 = runif(12))

v - NULL

for(i in 2:4) {
  kk - melt(Data[, c(1, i, i+1)], id.vars=month, variable_name=year)
  v[[i-1]] - kk[order(kk$year, decreasing=TRUE),]
}

out - do.call(cbind, v)

HTH
Patrick

Am 17.11.2010 15:03, schrieb Graves, Gregory:
 I have a file, each column of which is a separate year, and each row of each 
 column is mean precipitation for that month.  Looks like this (except it goes 
 back to 1964).

 monthX2000  X2001  X2002  X2003  X2004  X2005  X2006 X2007  X2008  
 X2009
 11.600  1.010  4.320  2.110  0.925  3.275  3.460 0.675  1.315  
 2.920
 22.960  3.905  3.230  2.380  2.720  1.880  2.430 1.380  2.480  
 2.380
 31.240  1.815  1.755  1.785  1.250  3.940 10.025 0.420  2.845  
 2.460
 43.775  1.350  2.745  0.170  0.710  2.570  0.255 0.425  4.470  
 1.250
 54.050  1.385  5.650  1.515 12.005  6.895  7.020 4.060  7.725  
 2.775
 68.635  8.900 15.715 12.680 16.270 12.605  7.095 7.025 10.465  
 7.345
 75.475  7.955  7.880  6.670  7.955  7.355  5.475 5.650  7.255  
 7.985
 88.435  5.525  7.120  6.250  7.150  7.610  5.525 6.500  6.275 
 10.405
 95.855  7.830  7.250  7.355  9.715  7.850  6.385 7.960  4.485  
 7.250
 10  7.965 11.915  6.735  8.125  7.855 10.465  4.340 6.165  2.400  
 3.240
 11  1.705  1.525  0.905  1.670  1.840  2.100  0.255 2.830  4.425  
 1.645
 12  2.335  0.840  0.795  1.890  0.145  1.700  0.260 2.160  2.300  
 2.220

 What I want to do is to stack 2008 data underneath 2009 data, 2007 under 
 2008, 2006 under 2007, etc.  I have so far figured out that I can do this 
 with the following clumsy approach:

 a=stack(yearmonth,select=c(X2009,X2008))
 b=stack(yearmonth,select=c(X2008,X2007))
 x=as.data.frame(c(a,b))
 write.table(x,clipboard,sep=   ,col.names=NA) #then paste this back 
 into Excel to get this


   values  ind values.1ind.1
 1 0.275   X2009   1.285   X2008
 2 0.41X2009   3.85X2008
 3 1.915   X2009   3.995   X2008
 4 1.25X2009   3.845   X2008
 5 8.76X2009   2.095   X2008
 6 8.65X2009   8.29X2008
 7 7.175   X2009   9.405   X2008
 8 7.19X2009   13.44   X2008
 9 8.13X2009   7.245   X2008
 101.46X2009   5.645   X2008
 112.56X2009   0.535   X2008
 125.01X2009   1.225   X2008
 131.285   X2008   0.72X2007
 143.85X2008   1.89X2007
 153.995   X2008   1.035   X2007
 163.845   X2008   2.86X2007
 172.095   X2008   3.785   X2007
 188.29X2008   9.62X2007
 199.405   X2008   9.245   X2007
 2013.44   X2008   5.595   X2007
 217.245   X2008   8.4 X2007
 225.645   X2008   6.705   X2007
 230.535   X2008   1.47X2007
 241.225   X2008   1.665   X2007


 Is there an easier, cleaner way to do this?  Thanks.

 Gregory A. Graves, Lead Scientist
 Everglades REstoration COoordination and VERification (RECOVER)
 Restoration Sciences Department
 South Florida Water Management District
 Phones:  DESK: 561 / 682 - 2429
 CELL:  561 / 719 - 8157

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


Re: [R] failure to access packages

2010-09-22 Thread Graves, Gregory

I am helping a fellow worker get R up and running, and he has run into a 
peculiar problem I've not encountered in previous install situations.

From the Rconsole menu choice, he can set CRAN mirror to USA CA2, but when he 
selects load packages a very truncated list of packages appears (many 
packages don't appear at all).

If he issues chooseCRANmirror() from the  prompt, he can still select USA 
CA2, but still can't see all the packages that are there.

If he issues 

local({pkg - select.list(sort(.packages(all.available = TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})

he gets this error:

Error in select.list(sort(.packages(all.available = TRIE)), graphics = TRUE :
   Unused argument(s)  (graphics = TRUE)

When I issue same command from  prompt, I get the expected list of packages.

Has anyone encountered this problem?  I've searched CRAN help, but got nowhere.



Gregory A. Graves, Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Restoration Sciences Department
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
       CELL:  561 / 719 - 8157

__
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] failure to access packages

2010-09-22 Thread Graves, Gregory
The problem R ver is 2.10.1 - I am using 2.11.1
Running windows xp sp3 - same system as what I use

The suggested solution is for the user to upgrade to 2.11.1 to resolve package 
incompatibilities

Gregory A. Graves, Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Restoration Sciences Department
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
       CELL:  561 / 719 - 8157


-Original Message-
From: Graves, Gregory 
Sent: Wednesday, September 22, 2010 11:45 AM
To: 'r-help@r-project.org'
Cc: King, Christopher
Subject: RE: failure to access packages


I am helping a fellow worker get R up and running, and he has run into a 
peculiar problem I've not encountered in previous install situations.

From the Rconsole menu choice, he can set CRAN mirror to USA CA2, but when he 
selects load packages a very truncated list of packages appears (many 
packages don't appear at all).

If he issues chooseCRANmirror() from the  prompt, he can still select USA 
CA2, but still can't see all the packages that are there.

If he issues 

local({pkg - select.list(sort(.packages(all.available = TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})

he gets this error:

Error in select.list(sort(.packages(all.available = TRIE)), graphics = TRUE :
   Unused argument(s)  (graphics = TRUE)

When I issue same command from  prompt, I get the expected list of packages.

Has anyone encountered this problem?  I've searched CRAN help, but got nowhere.



Gregory A. Graves, Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Restoration Sciences Department
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
       CELL:  561 / 719 - 8157

__
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] interpretation of stress in NMDS

2010-07-22 Thread Graves, Gregory
Among those users of Primer, stress values greater than 0.3 are
interpreted as questionable.  Using both isoMDS and metaMDS (vegan
package), the stress values returned are much higher using my own data
and using examples provided in R Help.  For example Rstress = 8.3, and
the stressplot r2 = 0.99 indicating (to me) that the ordination is OK.
I am guessing that the stress values across packages are not the same,
and googling about has not returned a satisfactory answer ... thus this
posting.  My concern being that reporting a stress value of 8 for what I
consider a satisfactory result may raise a few Primer-user's eyebrows.

 

Gregory A. Graves, Lead Scientist

Everglades REstoration COoordination and VERification (RECOVER) 

Restoration Sciences Department

South Florida Water Management District

Phones:  DESK: 561 / 682 - 2429 

   CELL:  561 / 719 - 8157

 


[[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] Exporting NMDS distance matris to csv

2010-07-20 Thread Graves, Gregory
If you submit these lines, you end up with variable vare.dis.  I want
to export vare.dis to csv.  Stuck I am.

 

library(vegan,logical.return = TRUE)  #return=true verifies package is
available

library(MASS,logical.return=TRUE)   #return=true verifies package is
available

data(varespec) #varespec is an example data file in the vegan package

vare.dis - vegdist(varespec)

vare.dis  #this is the triangular matrix I'd like to export

 

x=format.data.frame(vare.dis)  #nope, don't work

x=format(vare.dis) #nope

x=data.frame(vare.dis) #ditto

x=unknown.function(vare.dis)  #??? What is the unknown bit here to do
this?

 

#this is what I want to be able to do, i.e., write the matrix x out as
a csv

write.csv(x, file = temp.csv)

 

Gregory A. Graves, Lead Scientist

Everglades REstoration COoordination and VERification (RECOVER) 

Restoration Sciences Department

South Florida Water Management District

Phones:  DESK: 561 / 682 - 2429 

   CELL:  561 / 719 - 8157

 


[[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] nls model fitting errors

2010-06-10 Thread Graves, Gregory
What am I failing to understand here?

 

The script below works fine if the dataset being used is 

DNase1 - DNase[ DNase$Run == 1, ]  per the example given in
help(nlrob).  

Obviously, I am trying to understand how to use nls and nlrob to fit
curves to data using R.

 

#package=DAAG

attach(codling)

plot(pobs~dose)

#next command returns 'step factor reduced below min factor error'

m.nls - nls( pobs ~ a/(1 + exp(( b - log(dose) )/c ) ),

  data = codling,

  start = list( a = 3, b = 0, c = 1 ),

  trace = TRUE )

s-seq(min(pobs), max(pobs), .01)  

p.nls-predict(m.nls,list(pobs=s))  

lines(s,p.nls,col='blue')  #generates 'x and y lengths differ' error

 

Gregory A. Graves, Lead Scientist

Everglades REstoration COoordination and VERification (RECOVER) 

Restoration Sciences Department

South Florida Water Management District

Phones:  DESK: 561 / 682 - 2429 

   CELL:  561 / 719 - 8157

 


[[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] shading between two smoothed curves

2009-08-14 Thread Graves, Gregory
I will attempt to distill my problem down to a simpler one, the solution of 
which will hopefully lead me to the nirvana of complete understanding, i.e., 
inserting a polygon beneath an irregular line terminated by the x axis.

I 'know' that polygon will work -provided- I knew the xy coordinates of the 
line(s) beneath which I desire to create the polygon.  Unfortunately, I don't 
know how to get at that info.

Below is an example of a irregular line for which the xy coordinates are not 
known (i.e., at least not by me).  I assume my problem boils down to finding 
out how to extract the xy from that line.  

attach(cars)
plot(dist ~ speed)
scatter.smooth(speed, dist,family = gaussian,span = .2)



Gregory A. Graves
Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Watershed Division
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
 CELL:  561 / 719 - 8157
 

From: Debabrata Midya [mailto:debabrata.mi...@commerce.nsw.gov.au] 
Sent: Thursday, August 13, 2009 6:36 PM
To: Graves, Gregory
Cc: r-help@r-project.org
Subject: Re: [R] shading between two smoothed curves

Hi Gregory,
 
 I can plot out two nice curves using the following code, but I can't
figure out how to shade in the area lying between the two curves. 
 
Use polygon.
 
 ?polygon

 Graves, Gregory ggra...@sfwmd.gov 14/08/2009 4:17 am 
I have a set of 52 weekly values, one is the desired high lake stage for
a week, and the other is the desired low lake stage for each week.  It
looks like this:



week

High

Low

1

16

14.5

2

16

14.5

3

15.95

14.45

4

15.84

14.34

5

15.73

14.23

6

15.61

14.11

7

15.5

14

8

15.38

13.88

9

15.25

13.75

10

15.13

13.63




52

15

13.5



I can plot out two nice curves using the following code, but I can't
figure out how to shade in the area lying between the two curves.  I
also can't figure out how to adjust the line weight as lwd doesn't seem
to affect scatter.smooth.  Thanks in advance.



l=11  #lower ylim

h=17  #upper ylim

par(new=F)

good - complete.cases(week, high) #get rid of the NA error and only
using non-missing pairs

par(new=T)

scatter.smooth(week[good], high[good],family = gaussian,span = .2,
ylim=c(l,h), type='n', lwd=2, color=blue, ylab=, xlab=)  

good - complete.cases(week, low) 

par(new=T)

scatter.smooth(week[good], low[good],family = gaussian,span = .2,
ylim=c(l,h), type='n', lwd=2, color=red, ylab=Stage, feet,
xlab=Week of Year)  #loess, lower span makes more irregular

par(new=F)



Gregory A. Graves

Lead Scientist

Everglades REstoration COoordination and VERification (RECOVER) 

Watershed Division

South Florida Water Management District

Phones:  DESK: 561 / 682 - 2429 

 CELL:  561 / 719 - 8157

 




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


**

This email message, including any attached files, is confidential and
intended solely for the use of the individual or entity to whom it is
addressed. 

The NSW Department of Commerce prohibits the right to publish, 
copy, distribute or disclose any information contained in this email, 
or its attachments, by any party other than the intended recipient. 
If you have received this email in error please notify the sender and
delete it from your system.

No employee or agent is authorised to conclude any binding 
agreement on behalf of the NSW Department of Commerce by email. The
views or opinions presented in this email are solely those of the author
and do not necessarily represent those of the Department, 
except where the sender expressly, and with authority, states them to be
the views of NSW Department of Commerce.  

The NSW Department of Commerce accepts no liability for any loss or
damage arising from the use of this email and recommends that the
recipient check this email and any attached files for the presence of
viruses. 

**

__
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] shading between two smoothed curves

2009-08-14 Thread Graves, Gregory
Here is the solution for shading under a curve

attach(cars)  #example dataset
scatter.smooth(speed, dist,family = gaussian,span = .3, xlim=c(3,25), 
type='n')  #plot a curve (smoothed line)
gg-loess.smooth(speed,dist,family = gaussian,span = .3)  #put coordinates of 
smoothed line into 'gg'
DF-data.frame(gg) #convert gg into a dataframe; this dataframe has 50 rows
DF[51,]-c(25,0)  #add a 51st row with the desired bottom right corner of the 
polygon under the curve
DF[52,]-c(3,0)   #add a 52nd row with the desired bottom left corner of the 
polygon under the curve 
polygon(c(DF), col=gray, border = red)  # the shading

Here is NOT the solution for shading between 2 curves [I am going to use a 
crayon].

attach(cars)
#put 2 curves on the graph
scatter.smooth(speed, dist+25,family = gaussian,span = 
.3,xlim=c(3,25),type='n',ylim=c(0,120))  
par(new=T)
scatter.smooth(speed, dist-5,family = gaussian,span = 
.3,xlim=c(3,25),type='n',ylim=c(0,120))
#get the xy coords of the 2 curves
gg1-loess.smooth(speed,dist+25,family = gaussian,span = .3)
gg2-loess.smooth(speed,dist-5,family = gaussian,span = .3)
#stick the xy's into a dataframe and combine the 2 dataframes
DF1-data.frame(gg1) 
DF2-data.frame(gg2)
DFnew-do.call(rbind, list(DF1, DF2))
#Arrrgh
polygon(c(DFnew), col=gray, border = red)

Gregory A. Graves
Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Watershed Division
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
 CELL:  561 / 719 - 8157
 


-Original Message-
From: Jim Lemon [mailto:j...@bitwrit.com.au] 
Sent: Friday, August 14, 2009 8:47 AM
To: Graves, Gregory
Cc: r-help@r-project.org
Subject: Re: [R] shading between two smoothed curves

Graves, Gregory wrote:
 I will attempt to distill my problem down to a simpler one, the solution of 
 which will hopefully lead me to the nirvana of complete understanding, i.e., 
 inserting a polygon beneath an irregular line terminated by the x axis.

 I 'know' that polygon will work -provided- I knew the xy coordinates of the 
 line(s) beneath which I desire to create the polygon.  Unfortunately, I don't 
 know how to get at that info.

 Below is an example of a irregular line for which the xy coordinates are not 
 known (i.e., at least not by me).  I assume my problem boils down to finding 
 out how to extract the xy from that line.  

 attach(cars)
 plot(dist ~ speed)
 scatter.smooth(speed, dist,family = gaussian,span = .2)



   
Hi Gregory,
That's right, just call the underlying function (loess.smooth) and use 
str on the result. There should be x and y components that can be 
passed to lines.

Jim

__
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] shading between two smoothed curves

2009-08-14 Thread Graves, Gregory
Here is the solution for a shading between two curves. [much thanks to W.D.)

attach(cars)
#put 2 curves on the graph
scatter.smooth(speed, dist+25,family = gaussian,span = 
.3,xlim=c(3,25),type='n',ylim=c(0,120))  
par(new=T)
scatter.smooth(speed, dist-5,family = gaussian,span = 
.3,xlim=c(3,25),type='n',ylim=c(0,120))
#get the xy coords of the 2 curves
gg1-loess.smooth(speed,dist+25,family = gaussian,span = .3)
gg2-loess.smooth(speed,dist-5,family = gaussian,span = .3)
#stick the xy's into a dataframe and combine the 2 dataframes
DF1-data.frame(gg1) 
DF2-data.frame(gg2)
DFnew-do.call(rbind, list(DF1, DF2))
#add the shading
polygon(rbind(DF1, DF2[nrow(DF2):1,]), col=gray, border = red)

Gregory A. Graves
Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Watershed Division
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
 CELL:  561 / 719 - 8157
 

-Original Message-
From: Graves, Gregory 
Sent: Friday, August 14, 2009 1:38 PM
To: r-help@r-project.org
Subject: RE: [R] shading between two smoothed curves

Here is the solution for shading under a curve

attach(cars)  #example dataset
scatter.smooth(speed, dist,family = gaussian,span = .3, xlim=c(3,25), 
type='n')  #plot a curve (smoothed line)
gg-loess.smooth(speed,dist,family = gaussian,span = .3)  #put coordinates of 
smoothed line into 'gg'
DF-data.frame(gg) #convert gg into a dataframe; this dataframe has 50 rows
DF[51,]-c(25,0)  #add a 51st row with the desired bottom right corner of the 
polygon under the curve
DF[52,]-c(3,0)   #add a 52nd row with the desired bottom left corner of the 
polygon under the curve 
polygon(c(DF), col=gray, border = red)  # the shading

Here is NOT the solution for shading between 2 curves [I am going to use a 
crayon].

attach(cars)
#put 2 curves on the graph
scatter.smooth(speed, dist+25,family = gaussian,span = 
.3,xlim=c(3,25),type='n',ylim=c(0,120))  
par(new=T)
scatter.smooth(speed, dist-5,family = gaussian,span = 
.3,xlim=c(3,25),type='n',ylim=c(0,120))
#get the xy coords of the 2 curves
gg1-loess.smooth(speed,dist+25,family = gaussian,span = .3)
gg2-loess.smooth(speed,dist-5,family = gaussian,span = .3)
#stick the xy's into a dataframe and combine the 2 dataframes
DF1-data.frame(gg1) 
DF2-data.frame(gg2)
DFnew-do.call(rbind, list(DF1, DF2))
#Arrrgh
polygon(c(DFnew), col=gray, border = red)

Gregory A. Graves
Lead Scientist
Everglades REstoration COoordination and VERification (RECOVER) 
Watershed Division
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
 CELL:  561 / 719 - 8157
 


-Original Message-
From: Jim Lemon [mailto:j...@bitwrit.com.au] 
Sent: Friday, August 14, 2009 8:47 AM
To: Graves, Gregory
Cc: r-help@r-project.org
Subject: Re: [R] shading between two smoothed curves

Graves, Gregory wrote:
 I will attempt to distill my problem down to a simpler one, the solution of 
 which will hopefully lead me to the nirvana of complete understanding, i.e., 
 inserting a polygon beneath an irregular line terminated by the x axis.

 I 'know' that polygon will work -provided- I knew the xy coordinates of the 
 line(s) beneath which I desire to create the polygon.  Unfortunately, I don't 
 know how to get at that info.

 Below is an example of a irregular line for which the xy coordinates are not 
 known (i.e., at least not by me).  I assume my problem boils down to finding 
 out how to extract the xy from that line.  

 attach(cars)
 plot(dist ~ speed)
 scatter.smooth(speed, dist,family = gaussian,span = .2)



   
Hi Gregory,
That's right, just call the underlying function (loess.smooth) and use 
str on the result. There should be x and y components that can be 
passed to lines.

Jim

__
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] shading between two smoothed curves

2009-08-13 Thread Graves, Gregory
I have a set of 52 weekly values, one is the desired high lake stage for
a week, and the other is the desired low lake stage for each week.  It
looks like this:

 

week

High

Low

1

16

14.5

2

16

14.5

3

15.95

14.45

4

15.84

14.34

5

15.73

14.23

6

15.61

14.11

7

15.5

14

8

15.38

13.88

9

15.25

13.75

10

15.13

13.63




52

15

13.5

 

I can plot out two nice curves using the following code, but I can't
figure out how to shade in the area lying between the two curves.  I
also can't figure out how to adjust the line weight as lwd doesn't seem
to affect scatter.smooth.  Thanks in advance.

 

l=11  #lower ylim

h=17  #upper ylim

par(new=F)

good - complete.cases(week, high) #get rid of the NA error and only
using non-missing pairs

par(new=T)

scatter.smooth(week[good], high[good],family = gaussian,span = .2,
ylim=c(l,h), type='n', lwd=2, color=blue, ylab=, xlab=)  

good - complete.cases(week, low) 

par(new=T)

scatter.smooth(week[good], low[good],family = gaussian,span = .2,
ylim=c(l,h), type='n', lwd=2, color=red, ylab=Stage, feet,
xlab=Week of Year)  #loess, lower span makes more irregular

par(new=F)

 

Gregory A. Graves

Lead Scientist

Everglades REstoration COoordination and VERification (RECOVER) 

Watershed Division

South Florida Water Management District

Phones:  DESK: 561 / 682 - 2429 

 CELL:  561 / 719 - 8157

 

 


[[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 to use a list to create a plot

2009-07-21 Thread Graves, Gregory
I issued the following command to obtain the std dev for each month.

 

psd-numSummary(Sal, groups=month, statistics=c(sd))

 

which resulted in

 

 psd

sd   n  NA

1  6.930340  9367 2319

2  7.847003  10827 1008

3  5.962308  12988  404

4  3.632105  12576  384

5  3.328189  13030  362

6  10.101336129555

7  11.75958513071  321

8  10.27756612286 1105

9  8.561922  12286  674

10   9.252890  13343   27

11   9.568852  12591  369

12   9.622851  12020  946

 

 typeof(psd)

[1] list

 

I want plot sd versus column 1 (month of year) of the list psd.

 

The only way I can figure out how to do this is to manually copy the
table into Excel, reformat, and then export that back out as a new csv.
There has to be a better way?

 

 

Gregory A. Graves

Lead Scientist

REstoration COoordination and VERification (RECOVER) 

Watershed Division

South Florida Water Management District

Phones:  DESK: 561 / 682 - 2429 

 CELL:  561 / 719 - 8157

 

 

 


[[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] increase number of ticks on x axis of dates

2009-06-08 Thread Graves, Gregory
My x axis is a series of daily dates (e.g., 01/01/2000, 01/02/2000,
etc.) from 2000 to end of 2008.  The default only gives me 4 ticks.  I
want more.  Why doesn't this work?

sdate-as.POSIXct(strptime(date,format=%m/%d/%Y)) 
   
plot(ppt~sdate,type=l,ylim=c(0,47),col=1,lwd=1,pch=16,ylab=Salinity,
psu,xlab=Year,las=1,main=Duck Key Salinity,xaxt=n)

year.text=c(2001,2002,2003,2004, 2005, 2006, 2007,2008,
2009)

axis(1, at=c(1:9),labels=year.text)



Gregory A. Graves
Lead Scientist
REstoration COoordination and VERification (RECOVER) 
Watershed Division
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
 CELL:  561 / 719 - 8157
 

__
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] replacing default axis labels on a plot - SOLUTION

2009-05-15 Thread Graves, Gregory


The original problem posed was:

On 14/05/2009 7:31 AM, Graves, Gregory wrote:
 I have 3 columns:  flow, month, and monthname, where month is 1-12,
and
 monthname is name of month.  I can't get the plot to replace the 1-12
 with monthname using ticks.lab.  What am I doing wrong?
 
 plot(flow~factor(month),xlab=Month,ylab=Total Flow per Month,
 ylim=c(0,55000), ticks.lab=monthname)

Here is the solution to this:

# make a boxplot but suppress default labels on x axis with xaxt=n

plot(flow~factor(month),xlab=Month,ylab=Total Flow per Month,
ylim=c(0,55000), xaxt=n)  #NOTE xaxt

# create a vector containing month abbrevs with [[1]] suffix as follows

month.name-list(c(Jan, Feb, Mar, Apr, May, Jun, Jul,
Aug, Sep, Oct, Nov, Dec))[[1]]  

# place the 12 months on axis 1 (the x axis) as follows:
axis(1, at=1:12, labels=month.name)

Gregory A. Graves
Lead Scientist
REstoration COoordination and VERification (RECOVER) 
Watershed Division
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
 CELL:  561 / 719 - 8157
 

__
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] replacing default axis labels on a plot

2009-05-14 Thread Graves, Gregory
I have 3 columns:  flow, month, and monthname, where month is 1-12, and
monthname is name of month.  I can't get the plot to replace the 1-12
with monthname using ticks.lab.  What am I doing wrong?

plot(flow~factor(month),xlab=Month,ylab=Total Flow per Month,
ylim=c(0,55000), ticks.lab=monthname)

Thanks

Gregory A. Graves
Lead Scientist
REstoration COoordination and VERification (RECOVER) 
Watershed Division
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
 CELL:  561 / 719 - 8157
 
 

__
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] replacing default axis labels on a plot

2009-05-14 Thread Graves, Gregory
Thanks.  But ... Still don't get it.

Referring explicitly to the monthname column which had many entries
across many years did not work.  So taking your clue I created a new
variable list of names of month

month.name-list(c(Jan, Feb, Mar, Apr, May, Jun, Jul,
Aug, Sep, Oct, Nov, Dec))

then issued this command

plot(flow~factor(month),xlab=Month,ylab=Total Flow per Month,
ylim=c(0,55000), xaxt=n, axis(1, at=1:12, labels=month.name))

which gave this error

ERROR: 12, labels = month.name)

Gregory A. Graves
Lead Scientist
REstoration COoordination and VERification (RECOVER) 
Watershed Division
South Florida Water Management District
Phones:  DESK: 561 / 682 - 2429 
 CELL:  561 / 719 - 8157
 
 

-Original Message-
From: Duncan Murdoch [mailto:murd...@stats.uwo.ca] 
Sent: Thursday, May 14, 2009 8:12 AM
To: Graves, Gregory
Cc: r-help@r-project.org
Subject: Re: [R] replacing default axis labels on a plot

On 14/05/2009 7:31 AM, Graves, Gregory wrote:
 I have 3 columns:  flow, month, and monthname, where month is 1-12,
and
 monthname is name of month.  I can't get the plot to replace the 1-12
 with monthname using ticks.lab.  What am I doing wrong?
 
 plot(flow~factor(month),xlab=Month,ylab=Total Flow per Month,
 ylim=c(0,55000), ticks.lab=monthname)

ticks.lab is not a parameter to the plot.formula function.  You don't 
say where you found it described, but I'd suggest you read your source 
more closely, or just use xaxt=n in the plot call, and construct your 
own call to axis(), e.g. axis(1, at=1:12, labels=monthname).

Duncan Murdoch

 
 Thanks
 
 Gregory A. Graves
 Lead Scientist
 REstoration COoordination and VERification (RECOVER) 
 Watershed Division
 South Florida Water Management District
 Phones:  DESK: 561 / 682 - 2429 
  CELL:  561 / 719 - 8157
  
  
 
 __
 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.


[R] creating a matrix as input to lowess

2009-03-27 Thread Graves, Gregory
I have a very large file with many rows and columns.  I want to create a plot 
with lowess.  
 
If I try the following it works fine:

data(PrecipGL)

plot(PrecipGL)

lines(lowess(time(PrecipGL),PrecipGL),lwd=3, col=2)

 

In my file, 2 columns are nox and sdate, and are both typeof() = double.  
If I issue command 

Plot(nox~sdate) 

I can get a nice plot.

 

However if I try

lines(lowess(time(nox~sdate),nox~sdate),lwd=3, col=2)

it returns an error that it is not a matrix

 

if I try to extract these 2 columns into a matrix

mdat - matrix(date,nox, byrow=TRUE)

doesn't work, and search for help did not work, so am posting.  

 

Obviously I am a newbee here.  Thanks for any help!!

 
Gregory A. Graves
Lead Scientist
REstoration COoordination and VERification (RECOVER) Division
Everglades Restoration Resource Area
South Florida Water Management District
Phones:  DESK: 561 / 681 - 2563 x3730
 CELL:  561 / 719 - 8157
 

[[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] sdate-as.POSIXct(strptime(date,format=%m/%d/%Y %H:%M))

2009-01-01 Thread Graves, Gregory
Newbie here~
 
I've spent a ton of time on this, but have to admit I am stuck.  I've tried 
various combinations of strptime and the package CHRON, but still can't get 
there.
 
My simple task is that I want to plot salinity (S1 or S2) on y-axis and time on 
x-axis, but I want to use a lay-understandable representation of time (not 
Julian).  If I use the following command, I can make a plot using 
plot(S1~sdate), where:
 
sdate-as.POSIXct(strptime(date,format=%m/%d/%Y %H:%M))
 
... however, every 00:00 time winds up being an NA.  Here is an excerpt of the 
input data (this is a HUGE file):
 
indexDate   Julian S1  S2
24985   11/19/2006 00:00 39040.01 20.40 22.11  (this line winds up being an 
NA)
24986   11/19/2006 01:00 39040.05 20.42 22.22
24987   11/19/2006 02:00 39040.09 20.60 22.29
24988   11/19/2006 03:00 39040.14 20.62 22.21
24989   11/19/2006 04:00 39040.18 20.75 22.39

... an excerpt of the variable sdate winds up looking like this:
 
[35017] NA2007-09-08 01:00:00 EDT
[35019] 2007-09-08 01:00:00 EDT 2007-09-08 10:00:00 EDT
[35021] 2007-09-08 10:00:00 EDT 2007-09-08 11:00:00 EDT
[35023] 2007-09-08 11:00:00 EDT 2007-09-08 12:00:00 EDT
[35025] 2007-09-08 02:00:00 EDT 2007-09-08 02:00:00 EDT
[35027] 2007-09-08 03:00:00 EDT 2007-09-08 03:00:00 EDT
[35029] 2007-09-08 04:00:00 EDT 2007-09-08 04:00:00 EDT
[35031] 2007-09-08 05:00:00 EDT 2007-09-08 05:00:00 EDT
[35033] 2007-09-08 06:00:00 EDT 2007-09-08 06:00:00 EDT
[35035] 2007-09-08 07:00:00 EDT 2007-09-08 07:00:00 EDT
[35037] 2007-09-08 08:00:00 EDT 2007-09-08 08:00:00 EDT
[35039] 2007-09-08 09:00:00 EDT 2007-09-08 09:00:00 EDT
[35041] NA2007-09-09 01:00:00 EDT
[35043] 2007-09-09 01:00:00 EDT 2007-09-09 10:00:00 EDT
[35045] 2007-09-09 10:00:00 EDT 2007-09-09 11:00:00 EDT
[35047] 2007-09-09 11:00:00 EDT 2007-09-09 12:00:00 EDT
[35049] 2007-09-09 02:00:00 EDT 2007-09-09 02:00:00 EDT
[35051] 2007-09-09 03:00:00 EDT 2007-09-09 03:00:00 EDT
[35053] 2007-09-09 04:00:00 EDT 2007-09-09 04:00:00 EDT
[35055] 2007-09-09 05:00:00 EDT 2007-09-09 05:00:00 EDT
[35057] 2007-09-09 06:00:00 EDT 2007-09-09 06:00:00 EDT
[35059] 2007-09-09 07:00:00 EDT 2007-09-09 07:00:00 EDT
[35061] 2007-09-09 08:00:00 EDT 2007-09-09 08:00:00 EDT
[35063] 2007-09-09 09:00:00 EDT 2007-09-09 09:00:00 EDT
 
 
Gregory A. Graves
Lead Scientist
RECOVER Division
Everglades Restoration Resource Area
South Florida Water Management District
Phones:  DESK: 561 / 681 - 2563 x3730
 CELL:  561 / 719 - 8157
 

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