[R] Hydrology plots in R
Deepayan Sarkar
deepayan.sarkar at gmail.com
Fri Jul 23 12:17:23 CEST 2010
On Thu, Jul 22, 2010 at 7:56 AM, Sam Albers <tonightsthenight at gmail.com> wrote:
> Hello,
>
> I am trying to create a plot often seen in hydrodynamic work than includes a
> contour plot representing the water speed with arrows pointing in the
> direction of flow. Does anyone have any idea how I might add arrows based on
> wf$angle (in the example below) to the plot below?
>
> Thanks in advance!
>
> Sam
>
> library(lattice)
>
> speed <- runif(100, 0, 20)
> wf <- data.frame(speed)
> wf$width <- (1:10)
> wf$length <- rep(1:10, each=10)
> wf$angle <-runif(100, 0, 360)
>
> #How do I add arrows based on wf$angle within each coloured box to represent
> the direction of flow?
> #i don't have to use lattice. Just using it as an example.
> with(wf, contourplot(speed ~ width*length,
> region=TRUE,
> contour=FALSE
> ))
with(wf,
levelplot(speed ~ width * length,
angle = angle / 2 * pi,
region = TRUE,
contour = FALSE,
panel = function(x, y, ..., subscripts, angle, scale = 0.45) {
panel.levelplot(x, y, ..., subscripts = subscripts)
panel.arrows(x[subscripts], y[subscripts],
x[subscripts] + scale * cos(angle[subscripts]),
y[subscripts] + scale * sin(angle[subscripts]),
length = 0.07)
}))
-Deepayan
More information about the R-help
mailing list