[R] Plotting tidal speed and direction in R

Duncan Mackay mackay at northnet.com.au
Sat Jun 16 23:20:19 CEST 2012


Hi

The devil is in the detail of the components so here is a toy example 
to give you an idea in 2D but 5D
It is somewhat easier to interpret if you condition. You may be able 
to visualize in 3D not all can.
3D can be a problem if distinguishing points are 180 degrees apart in 
the preferred viewing aspect.
You can see 1 but not the other.

Here is an toy example using  lattice and latticeExtra packages

library(lattice)
library(latticeExtra)
set.seed(123)
data = cbind(expand.grid(lat = 
rep(1:4,4),long=rep(1:4,each=4),time=month.abb[1:4],direction=c("N","S","E","W") 
), speed= rnorm(4096))

useOuterStrips(wireframe(speed~long*lat|time*direction,data))
# or
useOuterStrips(levelplot(speed~long*lat|time*direction,data))
# or
useOuterStrips(contourplot(speed~long*lat|time*direction,data))

# OR
# from http://lmdvr.r-forge.r-project.org/figures/figures.html fig 
6.9  Adding useOuterStrips gives more space for panels.
# (code starts from 6.5)
library("locfit")

env <- environmental
env$ozone <- env$ozone^(1/3)
env$Radiation <- equal.count(env$radiation, 4)

fm1.env <- lm(ozone ~ radiation * temperature * wind, env)
fm2.env <-
loess(ozone ~ wind * temperature * radiation, env,
span = 0.75, degree = 1)
fm3.env <-
loess(ozone ~ wind * temperature * radiation, env,
parametric = c("radiation", "wind"),
span = 0.75, degree = 2)

fm4.env <- locfit(ozone ~ wind * temperature * radiation, env)
w.mesh <- with(env, do.breaks(range(wind), 50))
t.mesh <- with(env, do.breaks(range(temperature), 50))
r.mesh <- with(env, do.breaks(range(radiation), 3))
grid <-
expand.grid(wind = w.mesh,
temperature = t.mesh,
radiation = r.mesh)
grid[["fit.linear"]] <- predict(fm1.env, newdata = grid)
grid[["fit.loess.1"]] <- as.vector(predict(fm2.env, newdata = grid))
grid[["fit.loess.2"]] <- as.vector(predict(fm3.env, newdata = grid))
grid[["fit.locfit"]] <- predict(fm4.env, newdata = grid)

useOuterStrips(levelplot(fit.linear + fit.loess.1 + fit.loess.2 + 
fit.locfit ~ wind * temperature | radiation, data = grid))

Not knowing if the parameters are continuous makes a difference.

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au

I know you will have more data than this but perhaps a contour plot

At 05:49 17/06/2012, you wrote:

>On Jun 16, 2012, at 3:18 PM, Charles Berry wrote:
>
>>zoeita <zoe-allcock <at> live.co.uk> writes:
>>
>>>
>>>Hi,
>>>
>>>I have had a look around the forums and I can't seem to find
>>>anything that
>>>works with my data.  I have lats, longs, time, tidal speed and
>>>direction and
>>>need to plot this in an xy plot to determine changes over time.
>>>contour and
>>>cloud have been recommended to me as a way to do this but I can't
>>>figure out
>>>how to get 5 dimensions into this.  I want lat and long as my x and
>>>y, time
>>>as my z, direction as w and speed as different colours.  I imagine
>>>it's a
>>>lot easier than I think it is - I am very new to R.  Could anyone
>>>please
>>>help with a starting point for this?
>>
>>See
>>
>>http://blog.revolutionanalytics.com/2012/03/see-the-wind.html
>>
>>and the links therein.
>
>I suggest looking at 'arrow.plot' in package 'fields'. It will not be
>colored, but rather placing oriented arrows whose length is
>proportional to velocity. Your request for x, y, time coordinates may
>also lead you to the 'rgl' package, or to the 'animation' package.
>
>--
>
>
>David Winsemius, MD
>West Hartford, CT
>
>______________________________________________
>R-help at 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.
>



More information about the R-help mailing list