An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120705/a04445cf/attachment.pl>
function curve() swap axes
4 messages · Boudewijn Verkooijen, Duncan Murdoch, David Winsemius
On 05/07/2012 8:34 AM, Boudewijn Verkooijen wrote:
Dear all, I'm using the curve() function to plot discharge Q against water depth a. However, I would like to have a graph of water depth a plotted against discharge Q. How can this be done?
curve() is designed for plotting y vs x where y is a function of x, so I think you need to do it yourself. Simply compute a vector of "a" values using seq(), compute the corresponding Q values using your formula, and then use plot(Q, a, type="l") You can add the lwd and other arguments too if you like. Duncan Murdoch
Minimal working example:
S0 = 0.004
n = 0.04
tanalpha = 1.4/1.5
par(mar = c(5,5,1,1)) # b, l, t, r
curve((sqrt(S0)/n)*(0.035+(0.7+(x-0.1)/tanalpha)*(x-0.1))*((0.035+(0.7+(x-0.1)/tanalpha)*(x-0.1))/(2*sqrt((0.7/2)^2+0.1^2)+2*sqrt((x-0.1)^2+((x-0.1)/tanalpha)^2)))^(2/3),0.1,1.55,
lwd = 3, col = "royalblue4", ann = F, axes = T)
title(xlab = parse(text='a~bgroup("[", m, "]")'))
title(ylab = parse(text='Q~bgroup("[", m^3/s, "]")'))
box()
I tried to find the inverse function, but that doesn't seem to exist.
Thank you for support,
Boudewijn
[[alternative HTML version deleted]]
______________________________________________ R-help at 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.
On Jul 5, 2012, at 8:34 AM, Boudewijn Verkooijen wrote:
Dear all,
I'm using the curve() function to plot discharge Q against water
depth a.
However, I would like to have a graph of water depth a plotted against
discharge Q. How can this be done?
Minimal working example:
S0 = 0.004
n = 0.04
tanalpha = 1.4/1.5
par(mar = c(5,5,1,1)) # b, l, t, r
curve((sqrt(S0)/n)*(0.035+(0.7+(x-0.1)/
tanalpha)*(x-0.1))*((0.035+(0.7+(x-0.1)/tanalpha)*(x-0.1))/
(2*sqrt((0.7/2)^2+0.1^2)+2*sqrt((x-0.1)^2+((x-0.1)/
tanalpha)^2)))^(2/3),0.1,1.55,
lwd = 3, col = "royalblue4", ann = F, axes = T)
title(xlab = parse(text='a~bgroup("[", m, "]")'))
title(ylab = parse(text='Q~bgroup("[", m^3/s, "]")'))
box()
I tried to find the inverse function, but that doesn't seem to exist.
R does not perform computer algebra. If you wanted a numerical approach, you can construct a close fit to that function with approxfun() and then reverse the x and y roles to create an inverse. Actually, since curve returns a list with x and y components you could also do this: xycurv <- curve((sqrt(S0)/n)*(0.035+(0.7+(x-0.1)/ tanalpha)*(x-0.1))*((0.035+(0.7+(x-0.1)/tanalpha)*(x-0.1))/ (2*sqrt((0.7/2)^2+0.1^2)+2*sqrt((x-0.1)^2+((x-0.1)/ tanalpha)^2)))^(2/3),0.1,1.55, + lwd = 3, col = "royalblue4", ann = F, axes = T) plot(xycurv$y, xycurv$x)
David Winsemius, MD West Hartford, CT
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120706/18646c32/attachment.pl>