Anup,
You should have provided some additional information, such as that the
function 'hypsometric' is found in the hydroTSM contributed package.
Nevertheless, here's what I did (maybe not elegant, but it works) :
(1) at the R command prompt simply type hypsometric -- the source code for
the function 'hypsometric' will be written out
(2) copy this source code into a text file and save it as hypsometric2.R
(3) edit it as this or just copy this:
hypsometric2 <- function (x, band = 1, main = "Hypsometric Curve",
xlab "Relative Area above Elevation, (a/A)",
ylab = "Relative Elevation, (h/H)", col = "blue", ...)
{
if (class(x) != "SpatialGridDataFrame")
stop("Invalid argument: 'class(x)' must be
'SpatialGridDataFrame'")
band.error <- FALSE
if (is.numeric(band) | is.integer(band)) {
if ((band < 1) | (band > length(colnames(x@data))))
band.error <- TRUE
}
else if (is.character(band))
if (!(band %in% colnames(x@data)))
band.error <- TRUE
if (band.error)
stop("Invalid argument: 'band' does not exist in
'x' !")
mydem <- x@data[band]
z.min <- min(mydem, na.rm = TRUE)
z.max <- max(mydem, na.rm = TRUE)
x.dim <- x@grid@cellsize[1]
y.dim <- x@grid@cellsize[2]
max.area <- length(which(!is.na(mydem))) * x.dim * y.dim
res <- plot.stepfun(ecdf(as.matrix(mydem)), lwd = 0, cex.points = 0)
z.mean.index <- which(round(res$y, 3) == 0.5)[1]
z.mean <- res$t[z.mean.index]
relative.area <- (1 - res$y[-1])
relative.elev <- (res$t[-c(1, length(res$t))] - z.min)/(z.max -
z.min)
plot(relative.area, relative.elev, xaxt = "n", yaxt =
"n",
main = main, xlim = c(0, 1), ylim = c(0, 1), type = "l",
ylab = ylab, xlab = xlab, col = col, ...)
Axis(side = 1, at = seq(0, 1, by = 0.05), labels = TRUE)
Axis(side = 2, at = seq(0, 1, by = 0.05), labels = TRUE)
f <- splinefun(relative.area, relative.elev, method =
"monoH.FC")
hi <- integrate(f = f, lower = 0, upper = 1)
legend("topright", c(paste("Min Elev. :", round(z.min,
2),
"[m.a.s.l.]", sep = " "), paste("Mean
Elev.:", round(z.mean,
1), "[m.a.s.l.]", sep = " "), paste("Max Elev.
:", round(z.max,
1), "[m.a.s.l.]", sep = " "), paste("Max Area
:",
round(max.area/1e+06,
1), "[km2]", sep = " "), "",
paste("Integral value :",
round(hi$value, 3), sep = " "), paste("Integral error
:",
round(hi$abs.error, 3), sep = " ")), bty = "n", cex
= 0.9,
col = c("black", "black", "black"), lty =
c(NULL, NULL,
NULL, NULL))
curve_data<-data.frame(relative.area,relative.elev)
return(curve_data)
}
(4) rather than calling hypsometric(dem), for example, first do this:
source(hypsometric2.R)
(5) then call:
data<-hypsometric2(dem)
(6) you can see the x.y pairs by typing:
data
at the R prompt.
(7) verify that the data are what you expect, by typing this at the R
prompt:
plot(data)
which should give the same plot as hypsometric2(dem) and hypsometric(dem)
without the embellishments and labeling...
Tom
On Fri, Apr 26, 2013 at 8:52 AM, Anup khanal <zanup@hotmail.com> wrote:
> Dear exports,I have created a hypsometric curve (area-elevation curve) for
> my watershed by using simple command hypsometric(X,main="Hypsometric
> Curve", xlab="Relative Area above Elevation, (a/A)",
> ylab="Relative Elevation, (h/H)", col="blue")It plots
the hypsometric
> curve in "RGraphics window", My question is how can I export
values which
> is used to create this plot? I mean I want to know the value in y axis for
> certain x value.
> Thanks in advance !
>
> ..................Anup KhanalNorwegian Institute of science and Technology
> (NTNU)Trondheim, NorwayMob:(+47) 45174313
>
> [[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]]