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 )) -- ***************************************************** Sam Albers Geography Program University of Northern British Columbia 3333 University Way Prince George, British Columbia Canada, V2N 4Z9 phone: 250 960-6777 ***************************************************** [[alternative HTML version deleted]]
Sam, I recommend taking a look at the ggplot2 package. This page from the author's website contains an example of what I think you are trying to achieve: http://had.co.nz/ggplot2/geom_segment.html Obviously, this would require doing the whole plot in ggplot2, but that's not at all unpleasant. There's even a mailing list (on Google Groups) from ggplot2 with lots of friendly people to help. Best of luck, Jonathan On Thu, Jul 22, 2010 at 8:56 AM, Sam Albers <tonightsthenight@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 > )) > > -- > ***************************************************** > Sam Albers > Geography Program > University of Northern British Columbia > 3333 University Way > Prince George, British Columbia > Canada, V2N 4Z9 > phone: 250 960-6777 > ***************************************************** > > [[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]]
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
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