[R] function curve() swap axes
murdoch.duncan at gmail.com
Thu Jul 5 16:47:36 CEST 2012
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
plot(Q, a, type="l")
You can add the lwd and other arguments too if you like.
> 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
> lwd = 3, col = "royalblue4", ann = F, axes = T)
> title(xlab = parse(text='a~bgroup("[", m, "]")'))
> title(ylab = parse(text='Q~bgroup("[", m^3/s, "]")'))
> I tried to find the inverse function, but that doesn't seem to exist.
> Thank you for support,
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help