Programming Question (setting ylim generally)

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Programming Question (setting ylim generally)

ssefick
library(StreamMetabolism)

day <- (structure(c(10.08, 10.08, 10.05, 10.03, 10, 9.98, 9.96, 9.95,
9.95, 9.96, 9.96, 9.98, 10.01, 10.05, 10.06, 10.09, 10.11, 10.11,
10.13, 10.13, 10.15, 10.15, 10.13, 10.14, 10.11, 10.13, 10.14,
10.13, 10.12, 10.13, 10.14, 10.16, 10.18, 10.19, 10.23, 10.27,
10.33, 10.37, 10.45, 10.57, 10.6, 10.66, 10.73, 10.77, 10.84,
10.86, 10.87, 10.94, 10.98, 11.01, 11.05, 11.09, 11.11, 11.12,
11.14, 11.13, 11.15, 11.14, 11.13, 11.13, 11.12, 11.09, 11.08,
11.07, 11.05, 11.04, 11.03, 11.01, 10.99, 11, 10.94, 10.91, 10.86,
10.82, 10.77, 10.73, 10.7, 10.63, 10.59, 10.54, 10.47, 10.37,
10.3, 10.23, 10.18, 10.13, 10.09, 10.05, 10.02, 9.98, 9.96, 9.95,
9.94, 9.93, 9.94, 9.97), index = structure(c(13600.0006944444,
13600.0111111111, 13600.0215277778, 13600.0319444444, 13600.0423611111,
13600.0527777778, 13600.0631944444, 13600.0736111111, 13600.0840277778,
13600.0944444444, 13600.1048611111, 13600.1152777778, 13600.1256944444,
13600.1361111111, 13600.1465277778, 13600.1569444444, 13600.1673611111,
13600.1777777778, 13600.1881944444, 13600.1986111111, 13600.2090277778,
13600.2194444444, 13600.2298611111, 13600.2402777778, 13600.2506944444,
13600.2611111111, 13600.2715277778, 13600.2819444444, 13600.2923611111,
13600.3027777778, 13600.3131944444, 13600.3236111111, 13600.3340277778,
13600.3444444444, 13600.3548611111, 13600.3652777778, 13600.3756944444,
13600.3861111111, 13600.3965277778, 13600.4069444444, 13600.4173611111,
13600.4277777778, 13600.4381944444, 13600.4486111111, 13600.4590277778,
13600.4694444444, 13600.4798611111, 13600.4902777778, 13600.5006944444,
13600.5111111111, 13600.5215277778, 13600.5319444444, 13600.5423611111,
13600.5527777778, 13600.5631944444, 13600.5736111111, 13600.5840277778,
13600.5944444444, 13600.6048611111, 13600.6152777778, 13600.6256944444,
13600.6361111111, 13600.6465277778, 13600.6569444444, 13600.6673611111,
13600.6777777778, 13600.6881944444, 13600.6986111111, 13600.7090277778,
13600.7194444444, 13600.7298611111, 13600.7402777778, 13600.7506944444,
13600.7611111111, 13600.7715277778, 13600.7819444444, 13600.7923611111,
13600.8027777778, 13600.8131944444, 13600.8236111111, 13600.8340277778,
13600.8444444444, 13600.8548611111, 13600.8652777778, 13600.8756944444,
13600.8861111111, 13600.8965277778, 13600.9069444444, 13600.9173611111,
13600.9277777778, 13600.9381944444, 13600.9486111111, 13600.9590277778,
13600.9694444444, 13600.9798611111, 13600.9902777778), format =
structure(c("m/d/y",
"h:m:s"), .Names = c("dates", "times")), origin = structure(c(1,
1, 1970), .Names = c("month", "day", "year")), class = c("chron",
"dates", "times")), class = "zoo"))

plot.e <- function(b, w, x, y, z){
a <- window.chron(b, w, x, y, z)
low <- min(b*0.98)+5
high <- max(b*1.02)+5
plot(a, ylim=c(low, high))
lines(a*0.98, col="blue")
lines(a*1.02, col="red")
}

plot.e(day, "03/28/2007", "00:00:00", "03/28/2007", "23:46:00")

why do the low and high objects not set the ylim of the plotting function?

thanks

--
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

                                                                -K. Mullis

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Programming Question (setting ylim generally)

Gavin Simpson
On Fri, 2009-01-09 at 00:22 -0500, stephen sefick wrote:
> library(StreamMetabolism)
<snip />

> plot.e <- function(b, w, x, y, z){
> a <- window.chron(b, w, x, y, z)
> low <- min(b*0.98)+5
> high <- max(b*1.02)+5
> plot(a, ylim=c(low, high))
> lines(a*0.98, col="blue")
> lines(a*1.02, col="red")
> }
>
> plot.e(day, "03/28/2007", "00:00:00", "03/28/2007", "23:46:00")
>
> why do the low and high objects not set the ylim of the plotting function?
Err, they do. You are plotting 'a' which has (whilst debugging your
plot.e() )

Browse[1]> range(a)
[1]  9.93 11.15

You set the ylims to be (computed from 'b', why if plotting 'a'? and why
is 'low' +5, should it be -5?):

Browse[1]> low
[1] 14.7314
Browse[1]> high
[1] 16.373

And the plot I get has pretty labels/ticks that lie between 14.7 and
16.3, but as the plotted data lie outside the range of the y-axis you
don't see anything.

The figure is actually drawn with a bit of extra (4%) fudge on the x and
y limits as that is how all R plot work by default due to parameters
'xaxs' and 'yaxs'. If you want them to be exactly 'low' and 'high' then
setting yaxs="i" might help. See ?par

I suspect your plot.e needs to be something like this:

`plot.e` <- function(b, w, x, y, z){
a <- window.chron(b, w, x, y, z)
low <- min(a*0.98)-5
high <- max(a*1.02)+5
plot(a, ylim=c(low, high))
lines(a*0.98, col="blue")
lines(a*1.02, col="red")
}

So you are computing your ylims on a and you make low = foo - 5 not + 5.
At least then the lines you are drawing are displayed on the figure
region - the +/-5 in low and high seem a bit extreme, but that was what
you had so...

HTH

G
>
> thanks
>
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%


______________________________________________
[hidden email] 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.

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Programming Question (setting ylim generally)

ssefick
WOW, I am not going to post after midnight.  Thank you for your
response, and this is what I settled on.

`plot.e` <- function(b, w, x, y, z){
a <- window.chron(b, w, x, y, z)
low <- min(a*0.98)-(min(a)*0.04)
high <- max(a*1.02)+(max(a)*0.04)
plot(a, ylim=c(low, high))
lines(a*0.98, col="blue")
lines(a*1.02, col="red")
}

On Fri, Jan 9, 2009 at 5:38 AM, Gavin Simpson <[hidden email]> wrote:

> On Fri, 2009-01-09 at 00:22 -0500, stephen sefick wrote:
>> library(StreamMetabolism)
> <snip />
>> plot.e <- function(b, w, x, y, z){
>> a <- window.chron(b, w, x, y, z)
>> low <- min(b*0.98)+5
>> high <- max(b*1.02)+5
>> plot(a, ylim=c(low, high))
>> lines(a*0.98, col="blue")
>> lines(a*1.02, col="red")
>> }
>>
>> plot.e(day, "03/28/2007", "00:00:00", "03/28/2007", "23:46:00")
>>
>> why do the low and high objects not set the ylim of the plotting function?
>
> Err, they do. You are plotting 'a' which has (whilst debugging your
> plot.e() )
>
> Browse[1]> range(a)
> [1]  9.93 11.15
>
> You set the ylims to be (computed from 'b', why if plotting 'a'? and why
> is 'low' +5, should it be -5?):
>
> Browse[1]> low
> [1] 14.7314
> Browse[1]> high
> [1] 16.373
>
> And the plot I get has pretty labels/ticks that lie between 14.7 and
> 16.3, but as the plotted data lie outside the range of the y-axis you
> don't see anything.
>
> The figure is actually drawn with a bit of extra (4%) fudge on the x and
> y limits as that is how all R plot work by default due to parameters
> 'xaxs' and 'yaxs'. If you want them to be exactly 'low' and 'high' then
> setting yaxs="i" might help. See ?par
>
> I suspect your plot.e needs to be something like this:
>
> `plot.e` <- function(b, w, x, y, z){
> a <- window.chron(b, w, x, y, z)
> low <- min(a*0.98)-5
> high <- max(a*1.02)+5
> plot(a, ylim=c(low, high))
> lines(a*0.98, col="blue")
> lines(a*1.02, col="red")
> }
>
> So you are computing your ylims on a and you make low = foo - 5 not + 5.
> At least then the lines you are drawing are displayed on the figure
> region - the +/-5 in low and high seem a bit extreme, but that was what
> you had so...
>
> HTH
>
> G
>>
>> thanks
>>
> --
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>  Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
>  ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
>  Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
>  Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
>  UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>
>



--
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

                                                                -K. Mullis

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Programming Question (setting ylim generally)

Mike Prager
"stephen sefick" <[hidden email]> wrote:

> low <- min(a*0.98)-(min(a)*0.04)
> high <- max(a*1.02)+(max(a)*0.04)
> plot(a, ylim=c(low, high))

Unless I am misreading your example, this can be done a little
more compactly as:

plot(a, ylim = range(a * 0.94, a * 1.06))

--
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Programming Question (setting ylim generally)

Gabor Grothendieck
Or even:

plot(a, ylim = range(a) + 0.06 * c(-1, 1))


On Fri, Jan 9, 2009 at 2:07 PM, Mike Prager <[hidden email]> wrote:

> "stephen sefick" <[hidden email]> wrote:
>
>> low <- min(a*0.98)-(min(a)*0.04)
>> high <- max(a*1.02)+(max(a)*0.04)
>> plot(a, ylim=c(low, high))
>
> Unless I am misreading your example, this can be done a little
> more compactly as:
>
> plot(a, ylim = range(a * 0.94, a * 1.06))
>
> --
> Mike Prager, NOAA, Beaufort, NC
> * Opinions expressed are personal and not represented otherwise.
> * Any use of tradenames does not constitute a NOAA endorsement.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Programming Question (setting ylim generally)

ssefick
WOW, Gabor, that is fancy.  I have gotten better at this R thing, but
have far to go.  That is a neat solution.
thanks

Stephen


On Fri, Jan 9, 2009 at 2:22 PM, Gabor Grothendieck
<[hidden email]> wrote:

> Or even:
>
> plot(a, ylim = range(a) + 0.06 * c(-1, 1))
>
>
> On Fri, Jan 9, 2009 at 2:07 PM, Mike Prager <[hidden email]> wrote:
>> "stephen sefick" <[hidden email]> wrote:
>>
>>> low <- min(a*0.98)-(min(a)*0.04)
>>> high <- max(a*1.02)+(max(a)*0.04)
>>> plot(a, ylim=c(low, high))
>>
>> Unless I am misreading your example, this can be done a little
>> more compactly as:
>>
>> plot(a, ylim = range(a * 0.94, a * 1.06))
>>
>> --
>> Mike Prager, NOAA, Beaufort, NC
>> * Opinions expressed are personal and not represented otherwise.
>> * Any use of tradenames does not constitute a NOAA endorsement.
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>
> ______________________________________________
> [hidden email] 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.
>



--
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

                                                                -K. Mullis

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Programming Question (setting ylim generally)

Gabor Grothendieck
In reply to this post by Gabor Grothendieck
Berwin Turlach has pointed out that to
be equivalent to the original answer the
code should be:

plot(a, ylim = range(a) * (1 + 0.06 * c(-1,1)))

On Fri, Jan 9, 2009 at 2:22 PM, Gabor Grothendieck
<[hidden email]> wrote:

> Or even:
>
> plot(a, ylim = range(a) + 0.06 * c(-1, 1))
>
>
> On Fri, Jan 9, 2009 at 2:07 PM, Mike Prager <[hidden email]> wrote:
>> "stephen sefick" <[hidden email]> wrote:
>>
>>> low <- min(a*0.98)-(min(a)*0.04)
>>> high <- max(a*1.02)+(max(a)*0.04)
>>> plot(a, ylim=c(low, high))
>>
>> Unless I am misreading your example, this can be done a little
>> more compactly as:
>>
>> plot(a, ylim = range(a * 0.94, a * 1.06))
>>
>> --
>> Mike Prager, NOAA, Beaufort, NC
>> * Opinions expressed are personal and not represented otherwise.
>> * Any use of tradenames does not constitute a NOAA endorsement.
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>

______________________________________________
[hidden email] 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.