# [R] Visualising Vectors

Paul Murrell p.murrell at auckland.ac.nz
Mon Nov 3 22:59:15 CET 2003

```Hi

Sean O'Riordain wrote:
> Hi Laura,
>
> you should find some useful information in the latest R news Volume 3/2,
> October 2003
> http://cran.r-project.org/doc/Rnews/
>
> refer page 8 where Paul's figure 2 shows some novel symbols showing
> "China Sea Wind Speed, Direction and Temperature"... plotted by lat.&long.

Sorry Laura, I saw the original mail, got interested in the animation
part, then got distracted :)  As Sean has pointed out, the wind vectors
could be done like the example in the R News article, but that may not
be appropriate if there are very many to be drawn (could get slow).
Here's a modification of that example which just draws wind vectors as
simple arrows...

library(gridBase)
plot(chinasea\$lat, chinasea\$long, type="n",
xlab="latitude", ylab="longitude",
main="China Sea Wind Speed/Direction and Temperature")
speed <- 0.8*chinasea\$speed/14 + 0.2
temp <- chinasea\$temp/40
vps <- baseViewports()
par(new=TRUE)
push.viewport(vps\$inner, vps\$figure, vps\$plot)

# Just use a grid.arrows instead of a whole viewport per symbol
length <- 1 # "cm"
x1 <- unit(chinasea\$lat, "native") -
unit(0.5*length*cos(pi*chinasea\$dir/180), "cm")
y1 <- unit(chinasea\$long, "native") -
unit(0.5*length*sin(pi*chinasea\$dir/180), "cm")
x2 <- unit(chinasea\$lat, "native") +
unit(0.5*length*cos(pi*chinasea\$dir/180), "cm")
y2 <- unit(chinasea\$long, "native") +
unit(0.5*length*sin(pi*chinasea\$dir/180), "cm")
grid.arrows(grob=grid.segments(x1, y1, x2, y2),
length=unit(3, "mm"))

pop.viewport(3)

... This modification still requires gridBase;  the same effect could be
achieved with the base arrows() function, i.e., without gridBase, with a
little more effort required to calculate the "x" and "y" values for the
arrows.

You might also want to take a look at
http://sal.agecon.uiuc.edu/csiss/Rgeo/index.html
which gives an overview of the packages related to spatial statistics
that are available for R.  Somebody may have already done all the work
for you :)

Paul

> Laura Quinn wrote:
>
>> I sent a mail last week asking for some advise in relation to displaying
>> wind vectors on a contour map of a region. Whilst I have had some useful
>> feedback relating to the second part of this question (namely how to
>> animate a time series of still frames), I haven't recieved any advise on
>> how I might create the still images of the spatially distributed wind
>> vector data at any given time point.
>>
>> Firstly, is there a way in which I can input orographical information
>> (x,y,z co ords) into R to create a map, secondly, is there a way in which
>> i can superimpose a visual wind vector (i.e. arrow of certain length and
>> certain orientation) onto such a map?
>>
>> Laura
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

```