On 07/23/2010 12:56 AM, Sam Albers 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
))
Hi Sam,
Try this solution from the plotrix package:
par(mar=c(5,4,4,4))
color2D.matplot(matrix(wf$speed,ncol=10),extremes=c("#88eeee","#ee88ee"))
color.legend(10.6,0,11.1,10,seq(-5,25,by=5),color.scale(seq(-5,25,by=5),
extremes=c("#88eeee","#ee88ee")),gradient="y")
vectorField(matrix(wf$angle,ncol=10),matrix(0.5,nrow=10,ncol=10),
xpos=matrix(0.5:9.5,nrow=10,ncol=10,byrow=TRUE),
ypos=matrix(9.5:0.5,nrow=10,ncol=10),scale=0.5,vecspec="deg")
I probably don't have the values lined up correctly.
Jim
______________________________________________
[email protected] 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.