View source: R/sl.plot.vectors.R
sl.plot.vectors | R Documentation |
Plot vectors into a spheRlab plot.
sl.plot.vectors(pir, lon, lat, u, v, ref=median(sqrt(u^2+v^2)), ref.length.degrees=1, length.by.length=TRUE, lwd.by.length=FALSE, col.by.length=FALSE, col="black", colbar=sl.colbar(cols=c("blue","red"),N=256), colbar.breaks=NA, colbar.breaks.log=FALSE, lwd.ref=1, lty=1, head.line=TRUE, head.fill=FALSE, head.fill.line=TRUE, head.size=1/3, head.width=1, ref.args=NULL, ignore.visibility=FALSE)
plot.init.res |
a spheRlab plot specifics list as returned by |
lon |
a scalar, vector, matrix, or array specifying the longitudes of the points at which the vectors are centered. |
lat |
a scalar, vector, matrix, or array (same dimensions as |
u |
a scalar, vector, matrix, or array (same dimensions as |
v |
a scalar, vector, matrix, or array (same dimensions as |
ref |
a scalar specifying the magnitude ('speed') corresponding to the reference vector; default is |
ref.length.degrees |
a scalar specifying the length of the reference vector in degrees. |
length.by.length |
a logical value specifying whether to scale vector length linearly with its magnitude; if |
lwd.by.length |
a logical value specifying whether to scale vector line width linearly with its magnitude; if |
col.by.length |
a logical value specifying whether to vary vector colour with its magnitude; if |
col |
a colour for the vectors, used if |
colbar |
a spheRlab colourbar (as returned by |
colbar.breaks |
a numeric vector of length |
colbar.breaks.log |
a logical value indicating whether automatic colourbar breaks are to be placed logarithmically. Used only if |
lwd.ref |
a scalar specifying the line width of the reference vector; default is |
lty |
a scalar specifying the line type of the reference vector; default is |
head.line |
a logical value specifying whether or not to add the two typical lines bordering the arrow-point triangle; default is |
head.fill |
a logical value specifying whether or not to fill the arrow-point triangle; default is |
head.fill.line |
a logical value specifying whether or not to add all three lines bordering the arrow-point triangle; used only if |
head.size |
a scalar specifying the size of the arrow-point triangle in terms of length ratio. Default is |
head.width |
a scalar specifying the width of the arrow-point triangle relative to its length. Default is |
ref.args |
a list to specify where and what type of a reference arrow is drawn. Possible list elements (and their defaults) are: |
ignore.visibility |
a logical value indicating whether objects shall be attempted to be drawn completely even if classified partly or fully invisible, that is, outside the plot domain. |
The vectors are defined on the sphere, meaning that their length and orientation are distorted exactly in the way that any lines and polygons are distorted by the projection used. Accordingly, the vectors are drawn based on sl.plot.lines()
and sl.plot.polygon()
. The magnitude of the vectors (sqrt(u^2+v^2)
) can be coded by any combination of arrow length (linear), line width (linear), and colour (arbitrary colours and breaks).
If ref.args
is specified, a reference arrow with an optional circle around it is drawn, likewise on the sphere. This implies that the reference arrow is drawn in the map at a particular lon-lat location.
Helge Goessling
sl.plot.polygon
, sl.plot.lines
# define a cubed-sphere grid
N.xyz = 20
seq.xyz = seq(-1+1/N.xyz,1-1/N.xyz,2/N.xyz)
face = list(x=rep(-1,N.xyz^2),y=rep(seq.xyz,N.xyz),z=rep(seq.xyz,each=N.xyz))
x = c(face$x,-face$x,face$y,face$y,face$z,face$z)
y = c(face$y,face$y,face$z,face$z,face$x,-face$x)
z = c(face$z,face$z,face$x,-face$x,face$y,face$y)
lonlat = sl.xyz2lonlat(x=x, y=y, z=z)
# define a simple vector field with meridional component a function of longitude and zonal component constant
v = sin(3*lonlat$lon*2*pi/360) * 5
u = rep(2,length(v))
# define a colourbar
colbar = sl.colbar(c("blue","red"),N=8)
# plot vector field in lon-lat projection into the standard graphical device
pir = sl.plot.init(projection = "lonlat", do.init.device = FALSE)
sl.plot.naturalearth(pir, resolution = "coarse")
cb = sl.plot.vectors(pir = pir, lon = lonlat$lon, lat = lonlat$lat, u = u, v = v, ref = max(sqrt(u^2+v^2)), ref.length.degrees = 8, col.by.length = TRUE, colbar = colbar, ref.args = list(lon=-150,lat=0))
sl.plot.end(pir, do.close.device=FALSE)
# plot vector field in north polar projection into a pdf file
pir = sl.plot.init(projection = "polar", device = "pdf", file.name = "~/sl.plot.vectors.pdf")
sl.plot.naturalearth(pir, resolution = "coarse", what = "land", fill.col = "grey", polygon.borders=TRUE)
cb = sl.plot.vectors(pir = pir, lon = lonlat$lon, lat = lonlat$lat, u = u, v = v, ref.length.degrees = 5, col.by.length = TRUE, colbar = colbar, lwd.by.length=TRUE, head.fill = TRUE, ref.args = list(lon=-30,lat=50,circbox.type="circle",circbox.bgcol="grey"))
# if col.by.length=TRUE, you can also plot the colourbar to annotate the plot:
sl.plot.colbar(colbar, breaks = cb$breaks, labels.cex = 0.8, xshift = max(pir$xlim)-0.15, do.init=FALSE)
text("m/s", x = max(pir$xlim)-0.07, y = 0.3, cex = 0.8)
# (you can omit the reference vector by not specifying 'ref.args' in the call to sl.plot.vectors)
sl.plot.end(pir, do.close.device = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.