[R] Programming Question (setting ylim generally)
Gavin Simpson
gavin.simpson at ucl.ac.uk
Fri Jan 9 11:38:11 CET 2009
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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090109/b895b683/attachment-0002.bin>
More information about the R-help
mailing list