Title: | 'Utilities of Institute of Data Analyses and Process Design (www.zhaw.ch/idp)' |
---|---|
Description: | Different high-level graphics functions for displaying large datasets, displaying circular data in a very flexible way, finding local maxima, brewing color ramps, drawing nice arrows, zooming 2D-plots, creating figures with differently colored margin and plot region. In addition, the package contains auxiliary functions for data manipulation like omitting observations with irregular values or selecting data by logical vectors, which include NAs. Other functions are especially useful in spectroscopy and analyses of environmental data: robust baseline fitting, finding peaks in spectra, converting humidity measures. |
Authors: | Christoph Hofer [cre], Rene Locher [aut], Andreas Ruckstuhl [ctb] |
Maintainer: | Christoph Hofer <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.1.21 |
Built: | 2024-11-05 06:14:46 UTC |
Source: | CRAN |
Different high-level graphics functions for displaying large datasets, displaying circular data in a very flexible way, finding local maxima, brewing color ramps, drawing nice arrows, zooming 2D-plots, creating figures with differently colored margin and plot region. In addition, the package contains auxiliary functions for data manipulation like omitting observations with irregular values or selecting data by logical vectors, which include NAs. Other functions are especially useful in spectroscopy and analyses of environmental data: robust baseline fitting, finding peaks in spectra, converting humidity measures.
Rene Locher, Andreas Ruckstuhl et al. Maintainer: Christoph Hofer <[email protected]>
Draws a set of open or closed arrows which can be shaped by
many arguments. Arrows
is an extended version of
p.arrows
.
Arrows(x1, y1, x2, y2, size = 1, width = 1.2/4/cin, open = TRUE, sh.adj = 0.1, sh.lwd = 1, sh.col = par("fg"), sh.lty = 1, h.col = sh.col, h.col.bo = sh.col, h.lwd = sh.lwd, h.lty = sh.lty, verbose = FALSE)
Arrows(x1, y1, x2, y2, size = 1, width = 1.2/4/cin, open = TRUE, sh.adj = 0.1, sh.lwd = 1, sh.col = par("fg"), sh.lty = 1, h.col = sh.col, h.col.bo = sh.col, h.lwd = sh.lwd, h.lty = sh.lty, verbose = FALSE)
x1 , y1
|
Coordinates of points from which to draw. |
x2 , y2
|
Coordinates of points to which to draw. |
size |
Head size as a fraction of a character height. |
width |
Width of the arrow head. See argument |
open |
Defines if arrows are open or closed. |
sh.adj |
Defines gap between end of the shaft and the top of the head of the arrow (see details) |
sh.lwd |
Thickness of shaft. cf. |
sh.col |
Color of shaft. cf. |
sh.lty |
Line type of shaft. cf. |
h.col |
Color of head. |
h.col.bo |
Color of border of head. |
h.lwd |
Line width of border of head. |
h.lty |
Line type of border of head. |
verbose |
When TRUE, the width used is returned. |
Definition of sh.adj:
End of shaft at top of head,
End of shaft at bottom of head,
Gap between shaft and head,
Head is on the shaft.
This function is based on graphics
A value is only returned, when verbose == TRUE
.
The plotting device should not be resized manually after plotting as this changes in general the aspect ratio of the plot and deforms hereby the plotted arrows. The beauty of the arrows depends from the resolution of the device. The higher resolutions give better results.
Andreas Ruckstuhl, refined by Rene Locher
## a bunch of different arrows plot(c(0,10), c(0,10), type="n") Arrows(5, 5, 5,10, size=3, sh.lwd=5, sh.lty=2, h.lwd=5) Arrows(5, 5, 7.5, 9, size=3, open=TRUE, sh.adj=0.7, sh.lwd=5, sh.lty=2, h.col.bo="red",h.lwd=5) Arrows(5, 5, 9, 7.5, size=3, open=FALSE, sh.adj=1, sh.lwd=5, sh.col="blue", h.col.bo="red",h.lwd=2) Arrows(5, 5, 10, 5, size=2.5, width=1.5, open=FALSE, sh.adj=1, sh.lwd=7, sh.col="blue") Arrows(5, 5, 9, 2.5, size=4, open=FALSE, sh.lty=0, h.col.bo="black",h.lwd=5) Arrows(5, 5, 7.5, 1) Arrows(5, 5, 5, 0, size=2) Arrows(5, 5, 2.5, 1, size=2, width=1) ## vector field x<- runif( 20) y<- runif( 20) u<- 0.1+0.02*rnorm(20) v<- 0.1+0.02*rnorm(20) plot(x,y,xlim=range(c(x,x+u)),ylim=range(c(y,y+v)),type="n") Arrows(x,y,x+u,y+v,sh.col="blue")
## a bunch of different arrows plot(c(0,10), c(0,10), type="n") Arrows(5, 5, 5,10, size=3, sh.lwd=5, sh.lty=2, h.lwd=5) Arrows(5, 5, 7.5, 9, size=3, open=TRUE, sh.adj=0.7, sh.lwd=5, sh.lty=2, h.col.bo="red",h.lwd=5) Arrows(5, 5, 9, 7.5, size=3, open=FALSE, sh.adj=1, sh.lwd=5, sh.col="blue", h.col.bo="red",h.lwd=2) Arrows(5, 5, 10, 5, size=2.5, width=1.5, open=FALSE, sh.adj=1, sh.lwd=7, sh.col="blue") Arrows(5, 5, 9, 2.5, size=4, open=FALSE, sh.lty=0, h.col.bo="black",h.lwd=5) Arrows(5, 5, 7.5, 1) Arrows(5, 5, 5, 0, size=2) Arrows(5, 5, 2.5, 1, size=2, width=1) ## vector field x<- runif( 20) y<- runif( 20) u<- 0.1+0.02*rnorm(20) v<- 0.1+0.02*rnorm(20) plot(x,y,xlim=range(c(x,x+u)),ylim=range(c(y,y+v)),type="n") Arrows(x,y,x+u,y+v,sh.col="blue")
Converts cartesian coordinates (x
, y
to clock
coordinates (rho
, phi
)
cart2clock(x, y, circle)
cart2clock(x, y, circle)
x , y
|
Cartesian coordinates. |
circle |
Defines the full circle in the units of |
Be aware that in clock coordinates and polar coordinate the angle phi is differently defined!
Data frame with
rho |
Distance of point from center of coordinate system. |
phi |
Angle between North (12 o' clock), center and the point, measured clockwise. |
Rene Locher
## convert clock coordinates to cartesian coordinates xy <- clock2cart(rho=rep(1,33),phi=seq(0,to=360,length.out=33),circle=360) ## convert the cartesian coordinates back to clock coordinates rhophi <- cart2clock(xy$x,xy$y,circle=360) round(clock2cart(rhophi,circle=360)-xy) ## QED
## convert clock coordinates to cartesian coordinates xy <- clock2cart(rho=rep(1,33),phi=seq(0,to=360,length.out=33),circle=360) ## convert the cartesian coordinates back to clock coordinates rhophi <- cart2clock(xy$x,xy$y,circle=360) round(clock2cart(rhophi,circle=360)-xy) ## QED
Converts clock coordinates (rho
, phi
) to cartesian
coordinates (x
, y
).
clock2cart(rho, phi, circle)
clock2cart(rho, phi, circle)
rho |
Distance of point from center of coordinate system. |
phi |
Angle between North (12 o' clock), center and the point, measured clockwise. |
circle |
Defines the full circle in the units of |
Be aware that in clock coordinates and polar coordinate the angle phi is differently defined!
Data frame with
x , y
|
Cartesian coordinates. |
Rene Locher
## an easy way to plot a circle xy <- clock2cart(rho=rep(1,33),phi=seq(0,to=360,length.out=33),circle=360) plot(xy)
## an easy way to plot a circle xy <- clock2cart(rho=rep(1,33),phi=seq(0,to=360,length.out=33),circle=360) plot(xy)
Converts color names or values to hsv code.
col2hsv(col)
col2hsv(col)
col |
Vector of color code. |
Matrix with the rows
h |
Hue of hsv-Signal: 0=red, 1/3=green, 2/3=blue, 1=red. |
s |
Saturation of hsv-Signal: 0=white, 1=full color. |
v |
Value of hsv-Signal: 0=black, 1=full color. |
Rene Locher
col2hsv(c("blue","green","red"))
col2hsv(c("blue","green","red"))
Coerces a list with vectors of different length into a data.frame. Fills the shorter vectors with NA.
data.sheet(x)
data.sheet(x)
x |
List to be converted. |
This function is convenient for comparing / controling data in Lists whose components should have approximately the same length.
data.frame
Thomas Unternaehrer
data.sheet(list(a=1:5,b=1:4))
data.sheet(list(a=1:5,b=1:4))
Produces (and possibly draws) a Grid frame grob which is a legend that
can be placed in other Grid plots. draw.leg
is a
slightly enhanced version of draw.key
in
package lattice V 0.12-3.
draw.leg(key, draw=FALSE, vp=NULL)
draw.leg(key, draw=FALSE, vp=NULL)
key |
A list determining the key. See details below and the
documentation for |
draw |
logical, whether the grob is to be drawn. |
vp |
viewport |
Three new components are added to the list key
of the original code
in package lattice V 0.12-3: between.rows
,
between.title
, adj.title
. They allow to format the
legend in a more flexible way. To ease the use of draw.leg
, the
full description of draw.key
and the here
interesting part of xyplot
are also included:
The key essentially consists of a number of columns, possibly
divided into blocks, each containing some rows. The contents of the
key are determined by (possibly repeated) components named
“rectangles”, “lines”, “points” or “text”. Each of these
must be lists with relevant graphical parameters (see later)
controlling their appearance. The key
list itself can contain
graphical parameters, these would be used if relevant graphical
components are omitted from the other components.
The length (number of rows) of each such column (except “text”s)
is taken to be the largest of the lengths of the graphical
components, including the ones specified outside (see the entry for
rep
below for details on this). The “text” component has to
have a character or expression vector as its first component, and
the length of this vector determines the number of rows.
The graphical components that can be included in key
(and
also in the components named “text”, “lines”, “points” and
“rectangles” as appropriate) are:
cex=1
col="black"
lty=1
lwd=1
font=1
fontface
fontfamily
pch=8
adj=0
type="l"
size=5
angle=0
density=-1
adj
, angle
and density
are currently
unimplemented. size
determines the width of columns of
rectangles and lines in character widths. type
is relevant
for lines; "l"
denotes a line, "p"
denotes a point,
and "b"
and "o"
both denote both together.
Other possible components of key
are:
between
numeric vector giving the amount of space (character widths) surrounding each column (split equally on both sides),
title
string or expression giving a title for the key
rep
logical, defaults to TRUE
. By default, it's assumed that
all columns in the key (except the “text”s) will have the same
number of rows, and all components are replicated to be as long
as the longest. This can be suppressed by specifying
rep=FALSE
, in which case the length of each column will
be determined by components of that column alone.
cex.title
cex for the title
background
background color, defaults to default background
border
either a color for the border, or a logical. In the latter
case, the border color is black if border
is
TRUE
, and no border is drawn if it is FALSE
(the
default)
transparent=FALSE
logical, whether key area should have a transparent background
columns
the number of columns column-blocks the key is to be divided into, which are drawn side by side.
between.columns
Space between column blocks, in addition to between
.
between.rows
New argument: Space between rows.
between.title
New argument: Space between top row and title of legend.
adj.title
New argument: Adjustment of title in respect to body of
legend.
adj.title = 0
adjusts the title to the left,
adj.title = 1
adjusts the title to the right and
adj.title = 0.5
(=default) centers the title.
divide
Number of point symbols to divide each line when type
is
"b"
or "o"
in lines
.
A Grid frame object (that inherits from “grob”)
Deepayan Sarkar, modified by Rene Locher
require(grid) ## Legend 2 cm below and 1 cm left of the upper right corner grid.newpage() key <- draw.leg(key = list(rectangles = list(col=1:3, size = 2, lwd = 0.5), text = list(LETTERS[1:3]), cex = 1.2, between = 2, between.rows = 0.5, between.title = 0.7, title = "component", cex.title = 1.4, transparent = TRUE)) vp.key <- viewport(x = convertX(unit(1,"npc")-unit(1,"cm"),"cm"), y = convertY(unit(1,"npc")-unit(2,"cm"),"cm"), width=grobWidth(key), height=grobHeight(key), just=c("right","top")) pushViewport(vp.key) grid.draw(key) popViewport() ##---------------------------------------- ## Legend 1 cm above the lower left corner key <- draw.leg(key = list(rectangles = list(col=1:3, size = 4, lwd = 0.5), text=list(letters[1:3]), lines=list(col=1:3), cex=2, between=2, between.rows=0.5, between.title=0.7, title = "component", adj.title = 0, cex.title = 2.4, transparent = TRUE)) vp.key <- viewport(x = 0, y = unit(1,"cm"), width=grobWidth(key), height=grobHeight(key), just=c("left","bottom")) grid.newpage() pushViewport(vp.key) grid.draw(key) popViewport()
require(grid) ## Legend 2 cm below and 1 cm left of the upper right corner grid.newpage() key <- draw.leg(key = list(rectangles = list(col=1:3, size = 2, lwd = 0.5), text = list(LETTERS[1:3]), cex = 1.2, between = 2, between.rows = 0.5, between.title = 0.7, title = "component", cex.title = 1.4, transparent = TRUE)) vp.key <- viewport(x = convertX(unit(1,"npc")-unit(1,"cm"),"cm"), y = convertY(unit(1,"npc")-unit(2,"cm"),"cm"), width=grobWidth(key), height=grobHeight(key), just=c("right","top")) pushViewport(vp.key) grid.draw(key) popViewport() ##---------------------------------------- ## Legend 1 cm above the lower left corner key <- draw.leg(key = list(rectangles = list(col=1:3, size = 4, lwd = 0.5), text=list(letters[1:3]), lines=list(col=1:3), cex=2, between=2, between.rows=0.5, between.title=0.7, title = "component", adj.title = 0, cex.title = 2.4, transparent = TRUE)) vp.key <- viewport(x = 0, y = unit(1,"cm"), width=grobWidth(key), height=grobHeight(key), just=c("left","bottom")) grid.newpage() pushViewport(vp.key) grid.draw(key) popViewport()
Defines the General Appearance of rose plot.
general.control(stacked = FALSE, rose.rad = NULL, rose.x = NULL, rose.y = NULL, mar = rep(0.3, 4), rev.col = FALSE, shift = 0, cex = 1, col = NULL, lty = 1:3, lwd = 1, type = "s")
general.control(stacked = FALSE, rose.rad = NULL, rose.x = NULL, rose.y = NULL, mar = rep(0.3, 4), rev.col = FALSE, shift = 0, cex = 1, col = NULL, lty = 1:3, lwd = 1, type = "s")
stacked |
|
rose.rad , rose.x , rose.y
|
Approximate length of radius, x- and
y-position of rose. Default units are mm but any valid grid unit
might be chosen (cf. |
mar |
Margin around the plotting area. Default units are
|
rev.col |
|
shift |
Shifts the plot in clockwise direction by this
angle. Units of |
cex |
Basic size of characters in the plot. |
col |
Colors of lines when |
lty , lwd
|
Line type and line width. When |
type |
1-character string giving the type of plot desired: |
Returns the arguments conveniently packaged up in a list to supply the
general arguments for plot.rose
.
Rene Locher
general.control()
general.control()
The function accepts one- or two dimensional data, checks them for compatibility and gives a dataframe back.
getXY(x, y = NULL, unidim.allowed = TRUE)
getXY(x, y = NULL, unidim.allowed = TRUE)
x |
Vector, matrix, dataframe or list. If |
y |
Optional vector of the same length as |
unidim.allowed |
Logical.
|
Input is checked for compatibility: When x
is a list, the
first two elements must have identical length. When y
is
defined, x
must be one dimensional and must have the same
length as argument y
. When onedim.allowed
is
FALSE, input must be twodimensional.
When input is one dimensional and unidim
is TRUE, y
gives the numbers of elements back.
Function works similar to xy.coords
dataframe with the components x
and y
Rene Locher
getXY(3:4, 1:2) getXY(matrix(1:4,ncol=2)) getXY(as.data.frame(matrix(1:4,ncol=2))) getXY(4:1) getXY(list(a=1:2,b=9:10))
getXY(3:4, 1:2) getXY(matrix(1:4,ncol=2)) getXY(as.data.frame(matrix(1:4,ncol=2))) getXY(4:1) getXY(list(a=1:2,b=9:10))
Defines the appearance of the guiding elements of rose plots such as circles, rays and labels.
grid.control(circ.n = 4, circ.r = NULL, circ.col = "gray30", circ.lwd = 0.5, circ.cex = 0.8, circ.between = 0.3, circ.dir = pi/16 * 9, circ.sub.n = NULL, circ.sub.r = NULL, circ.sub.col = "gray70", circ.sub.lwd = 0.5, cyclVar.lab = c("N","NE","E","SE","S","SW","W","NW"), cyclVar.cex = 1.2, cyclVar.between = 0, cyclVar.centered = TRUE, ray.lim = NULL, ray.n = 8)
grid.control(circ.n = 4, circ.r = NULL, circ.col = "gray30", circ.lwd = 0.5, circ.cex = 0.8, circ.between = 0.3, circ.dir = pi/16 * 9, circ.sub.n = NULL, circ.sub.r = NULL, circ.sub.col = "gray70", circ.sub.lwd = 0.5, cyclVar.lab = c("N","NE","E","SE","S","SW","W","NW"), cyclVar.cex = 1.2, cyclVar.between = 0, cyclVar.centered = TRUE, ray.lim = NULL, ray.n = 8)
circ.n , circ.r
|
Number of (main)circles or, alternatively, radius of circles to be drawn, which will be labeled. |
circ.col , circ.lwd
|
Color and line width of circles. |
circ.cex |
Character size of labels of main circles in
multiples of |
circ.between |
Distance between labels of the main circle and the circle itself in multiples of circ.cex. |
circ.dir |
Direction along which the labels of the main circles should be drawn, measured clockwise as radian from North. |
circ.sub.n , circ.sub.r
|
Number of subcircle intervals between two main circles, or, alternatively, the radii of all subcircles. |
circ.sub.col , circ.sub.lwd
|
Color and line width of subcircles. |
cyclVar.lab |
Labels of cyclic variable placed along the outmost circle. |
cyclVar.cex |
Charactersize of labels of cyclic
variable in multiples of cex as defined in
|
cyclVar.between |
Distance between labels of the cyclic
variable and the outmost circle of the rose in multiples of
|
cyclVar.centered |
Labels are positioned relative
to their center. |
ray.lim |
Defines the values for the center and the maximum radius in user coordinates. Be careful with specifying the center different from 0 as this might result in misleading roses. |
ray.n |
Number of rays. |
Returns the arguments conveniently packaged up in a list to supply the arguments for the grid appearance of rose plot.
Rene Locher
grid.control()
grid.control()
Converting dew point (of water in air) into vapor pressure or relative humidity and vice versa.
hr(T, Td, warn = TRUE) pw(Td, warn = TRUE) pw.ai(Td, warn = TRUE) pw.aw(Td, warn = TRUE) Td(pw = NULL, T = NULL, hr = NULL, warn = TRUE) Td.aw(pw = NULL, T = NULL, hr = NULL, warn = TRUE) Tf.ai(pw = NULL, T = NULL, hr = NULL, warn = TRUE)
hr(T, Td, warn = TRUE) pw(Td, warn = TRUE) pw.ai(Td, warn = TRUE) pw.aw(Td, warn = TRUE) Td(pw = NULL, T = NULL, hr = NULL, warn = TRUE) Td.aw(pw = NULL, T = NULL, hr = NULL, warn = TRUE) Tf.ai(pw = NULL, T = NULL, hr = NULL, warn = TRUE)
hr |
Relative humidity in |
T |
Temperature of air in |
Td |
Dew point of air in |
pw |
Saturation vapour pressure in |
warn |
When |
All vapour pressures correspond to pure water vapour and are not adjusted to water vapour in air.
hr
transforms dew point above ice / water at a certain temperature into
relative humidity ().
pw
transforms dew point into saturation vapour pressure above ice
() and above water (
) respectively.
pw.ai
transforms dew point into saturation vapour
pressure above ice ().
pw.aw
transforms dew point into saturation vapour
pressure above liquid water ().
Td
transforms vapour pressure or relative humidity and
temperature into frost point above ice () and dew point above water (
) respectively.
Td.aw
transforms vapour pressure or relative humidity and
temperature into dew point above water ().
Tf.ai
transforms vapour pressure or relative humidity and
temperature into frost point above ice ().
Rene Locher
Guide to Meteorological Instruments and Methods of Observation, WMO, WMO-No. 8, Seventh edition, 2008, updated 2010, 1.4-29 Annex 4.B
pw(Td = c(-65, -45, 0, 30, 60)) Td(pw = pw(c(-20, 0, 20))) hr(T = c(20, 30, 40), Td = c(0, 20, 30)) ## [1] 26.20257 55.09561 57.46519 hr(T = seq(0, 60, 5), Td = 0)
pw(Td = c(-65, -45, 0, 30, 60)) Td(pw = pw(c(-20, 0, 20))) hr(T = c(20, 30, 40), Td = c(0, 20, 30)) ## [1] 26.20257 55.09561 57.46519 hr(T = seq(0, 60, 5), Td = 0)
Produces color ramps which change simultanously hues, saturation and
values as defined in the hsv
modus. This
allows to produce especially smooth transitions from one color to the
next. The default color ramp starts with light blue, continues with
green, yellow, red and ends with dark violet.
IDPcolorRamp(n, colInt = data.frame(h = c(0.47, 0.28, 0.16, 0, 1, 0.8), s = c(0.31, 0.55, 0.7, 0.8, 0.8, 1), v = c(1, 1, 1, 1, 1, 0.4)), fr = c(0.27, 0.27, 0.27, 0))
IDPcolorRamp(n, colInt = data.frame(h = c(0.47, 0.28, 0.16, 0, 1, 0.8), s = c(0.31, 0.55, 0.7, 0.8, 0.8, 1), v = c(1, 1, 1, 1, 1, 0.4)), fr = c(0.27, 0.27, 0.27, 0))
n |
Total number of different colors in color ramp. |
colInt |
Data.frame or matrix with the columns h,s & v which defines the Intervals for individual color subramps, with nrow(colInt) = nsr+1 with nsr>1. See details |
fr |
Fraction of the colors in each of the first nsr-1 subramps. |
The function distributes the number of colors in the subramps, given
the fractions fr, as smoothly as possible. The default arguments are
optimized to most distinct colors possible, also for very small
n
. There is at least one color in the first and the last
subramp.
Definition of hsv code:
h
Hue of hsv-Signal: 0=red, 1/3=green, 2/3=blue, 1=red.
s
Saturation of hsv-Signal: 0=white, 1=full color.
v
Value of hsv-Signal: 0=black, 1=full color.
A vector of n
colors.
If there are subramps which are not adjacent in the color space (as is here the case for red and violet), you need a virtual subramp (here from h=0.00 to h=1.00) with corresponding fraction fr == 0.
Rene Locher
IDPcolorRamp(10) ## Default IDPcolorRamp in 21 colors n <- 21 showColors(IDPcolorRamp(n),border=FALSE) ## colorRamp optimized to return at equidistant indices the colors ## light blue, light green, yellow, orange, red, dark violet ## works fine with n > 7 cInt <- data.frame(h = c(0.47, 0.28, 0.16, 0, 1, 0.8), s = c(0.31, 0.55, 0.7, 0.8, 0.8, 1), v = c(1, 1, 1, 1, 1, 0.5)) fr <- c(0.15, 0.25, 0.45, 0.0) ii <- seq(1,n,length.out=6) ## colors at equidistant indices showColors(IDPcolorRamp(n, colInt = cInt, fr =fr)[ii], border=FALSE) ## Alternative ramp in 21 colors showColors(IDPcolorRamp(n, colInt = cInt, fr =fr), border=FALSE)
IDPcolorRamp(10) ## Default IDPcolorRamp in 21 colors n <- 21 showColors(IDPcolorRamp(n),border=FALSE) ## colorRamp optimized to return at equidistant indices the colors ## light blue, light green, yellow, orange, red, dark violet ## works fine with n > 7 cInt <- data.frame(h = c(0.47, 0.28, 0.16, 0, 1, 0.8), s = c(0.31, 0.55, 0.7, 0.8, 0.8, 1), v = c(1, 1, 1, 1, 1, 0.5)) fr <- c(0.15, 0.25, 0.45, 0.0) ii <- seq(1,n,length.out=6) ## colors at equidistant indices showColors(IDPcolorRamp(n, colInt = cInt, fr =fr)[ii], border=FALSE) ## Alternative ramp in 21 colors showColors(IDPcolorRamp(n, colInt = cInt, fr =fr), border=FALSE)
Produces an image lag plot matrix of large timeseries where the colors encode the density of the points in the lag plots.
ilagplot(x, set.lags = 1, pixs = 1, zmax = NULL, ztransf = function(x){x}, colramp = IDPcolorRamp, mfrow=NULL, cex=par("cex"), main = NULL, d.main = 1, cex.main = 1.5*par("cex.main"), legend = TRUE, d.legend = 1, cex.axis = par("cex.axis"), las = 1, border=FALSE, mar = c(2,2,2,0), oma = rep(0,4)+0.1, mgp = c(2,0.5,0)*cex.axis, tcl = -0.3, ...)
ilagplot(x, set.lags = 1, pixs = 1, zmax = NULL, ztransf = function(x){x}, colramp = IDPcolorRamp, mfrow=NULL, cex=par("cex"), main = NULL, d.main = 1, cex.main = 1.5*par("cex.main"), legend = TRUE, d.legend = 1, cex.axis = par("cex.axis"), las = 1, border=FALSE, mar = c(2,2,2,0), oma = rep(0,4)+0.1, mgp = c(2,0.5,0)*cex.axis, tcl = -0.3, ...)
x |
ts object or ordinary vector |
set.lags |
vector of lags to be displayed |
pixs |
Pixel size in mm |
zmax |
Maximum counts per Pixel to be plotted. When NULL each
lag plot has its individual scale. If a number >= maximum number of
counts per pixel is supplied, the scale will be identical for all
lag plots. The maximum of the number per pixel is delivered by the
return value. Beware: |
ztransf |
Function to transform the counts. The user has to make sure that the transformed counts lie in the range [0,zmax], where zmax is any positive number (>=2). |
colramp |
Color ramp to encode the density of the points within a pixel |
mfrow |
See Argument |
cex |
See Argument |
main |
Title |
d.main |
Vertical distance between upper border of scatter plots and the title line in multiples of title height. |
cex.main |
Magnification used for title relative to the current setting of cex. |
legend |
Logical. When |
d.legend |
Horizontal distance between right border of scatter plots and legend in multiples of title height. |
cex.axis |
Magnification used for axis annotation relative to the current setting of cex. |
las |
Orientation of labels on axes. |
border |
Logical. When |
mar , oma
|
Margin and outer margin respectively.
Cf. |
mgp , tcl
|
Cf. |
... |
Additional arguments to |
Code is based on R function lag.plot
V1.7.
Tip: Legend looks better when mar
is defined symmetrically.
Maximum number of counts per Pixel found.
When you get the error message "Zmax too small! Densiest aereas are out of range!" you must run the function with identical parameters but without specifying zmax. The value returned gives you the minimum value allowed for zmax.
Andreas Ruckstuhl, refined by Rene Locher
if(require(SwissAir)) { data(AirQual) ilagplot(AirQual[,c("ad.O3")],set.lags = 1:4, ztransf = function(x){x[x<1] <- 1; log2(x)}, main = "Low correlation") Ox <- AirQual[,c("ad.O3","lu.O3","sz.O3")]+ AirQual[,c("ad.NOx","lu.NOx","sz.NOx")]- AirQual[,c("ad.NO","lu.NO","sz.NO")] names(Ox) <- c("ad","lu","sz") ilagplot(Ox$ad,set.lags = 1:4, ztransf = function(x){x[x<1] <- 1; log2(x)}, main = "High correlation") ## cf. ?AirQual for the explanation of the physical ## and chemical background } else print("Package SwissAir is not available")
if(require(SwissAir)) { data(AirQual) ilagplot(AirQual[,c("ad.O3")],set.lags = 1:4, ztransf = function(x){x[x<1] <- 1; log2(x)}, main = "Low correlation") Ox <- AirQual[,c("ad.O3","lu.O3","sz.O3")]+ AirQual[,c("ad.NOx","lu.NOx","sz.NOx")]- AirQual[,c("ad.NO","lu.NO","sz.NO")] names(Ox) <- c("ad","lu","sz") ilagplot(Ox$ad,set.lags = 1:4, ztransf = function(x){x[x<1] <- 1; log2(x)}, main = "High correlation") ## cf. ?AirQual for the explanation of the physical ## and chemical background } else print("Package SwissAir is not available")
The density of points in a scatter plot is encoded by color.
Image(x, y = NULL, pixs = 1, zmax = NULL, ztransf = function(x){x}, colramp = IDPcolorRamp, factors = c(FALSE, FALSE), matrix = FALSE)
Image(x, y = NULL, pixs = 1, zmax = NULL, ztransf = function(x){x}, colramp = IDPcolorRamp, factors = c(FALSE, FALSE), matrix = FALSE)
x , y
|
Coordinates of points whose density is plotted. If
|
pixs |
Size of pixel in x- and y-direction in [mm] on the
plotting device. When |
zmax |
Maximum number of counts per pixel in the plot. When
|
ztransf |
Function to transform the number of counts per
pixel, which will be mapped by the function in
|
colramp |
Color ramp to encode the number of the counts within a pixel by color. |
factors |
Vector of logicals indicating whether |
matrix |
Boolean. Should all counts be returned in a xyz-matrix or just the maximum. |
Before calling Image
a plot must have been created by, e.g.,
calling plot(x,y,type="n")
. This function ensures
by default that the pixel has the same size in x- and y-direction. As
a drawback, pixels may be unequally spaced, when there are only very
few distinct (integer) values in x- or y-direction. When this is the
case, the corresponding dimension should be declared as a factor.
(cf. argument factors
).
This function is based on graphics
Maximum number of counts per pixel found (matrix = FALSE
) or
the full matrix.
Andreas Ruckstuhl, Rene Locher
ipairs
, ilagplot
,
iplot
, image
plot.default(iris$Species, iris$Petal.Width, xlim=c(0.5,3.5), type="n", axes=FALSE) axis(1, at=1:3, labels=levels(iris$Species)) axis(2) Image(iris$Species, iris$Petal.Width, pixs=3) ## x <- rnorm(10000) y <- rnorm(10000, 10) plot(x+y, y, type="n") Image(x+y, y) abline(a=0, b=1) ## The above can be merged to iplot(x+y, y, legend=FALSE, oma=c(5, 4, 4, 2) + 0.1) abline(a=0, b=1)
plot.default(iris$Species, iris$Petal.Width, xlim=c(0.5,3.5), type="n", axes=FALSE) axis(1, at=1:3, labels=levels(iris$Species)) axis(2) Image(iris$Species, iris$Petal.Width, pixs=3) ## x <- rnorm(10000) y <- rnorm(10000, 10) plot(x+y, y, type="n") Image(x+y, y) abline(a=0, b=1) ## The above can be merged to iplot(x+y, y, legend=FALSE, oma=c(5, 4, 4, 2) + 0.1) abline(a=0, b=1)
Produces an image scatter plot matrix of large datasets where the colors encode the density of the points in the scatter plots.
ipairs(x, pixs = 1, zmax = NULL, ztransf=function(x){x}, colramp = IDPcolorRamp, cex = par("cex"), lab.diag, cex.diag = NULL, main = NULL, d.main = 1.5, cex.main = 1.5*par("cex.main"), legend = TRUE, d.legend = 1.5, cex.axis = 0.8*par("cex.axis"), nlab.axis = 5, minL.axis = 2, las = 1, border = FALSE, mar = rep(0,4), oma = c(3,3,1,0), mgp = c(2,0.5,0)*cex.axis, tcl = -0.3, ...)
ipairs(x, pixs = 1, zmax = NULL, ztransf=function(x){x}, colramp = IDPcolorRamp, cex = par("cex"), lab.diag, cex.diag = NULL, main = NULL, d.main = 1.5, cex.main = 1.5*par("cex.main"), legend = TRUE, d.legend = 1.5, cex.axis = 0.8*par("cex.axis"), nlab.axis = 5, minL.axis = 2, las = 1, border = FALSE, mar = rep(0,4), oma = c(3,3,1,0), mgp = c(2,0.5,0)*cex.axis, tcl = -0.3, ...)
x |
data.frame or matrix |
pixs |
Pixel size in mm on the plotting device. |
zmax |
Maximum number of counts per pixel in the plot. When NULL, each scatter plot has its individual scale. If a number >= maximum number of counts per pixel is supplied, the scale will be identical for all scatter plots. The maximum number of counts per pixel is delivered by the return value. |
ztransf |
Function to transform the counts per
pixel, which will be mapped by the function in
|
colramp |
Color ramp to encode the number of counts within a pixel. |
cex |
See Argument |
lab.diag |
Labels of columns, written into the diagonal of the
matrix. When |
cex.diag |
Magnification used for text in diagonal relative to
the current setting of cex.
When |
main |
Titel. When |
d.main |
Vertical distance between upper border of scatter plots and the title line in multiples of title height. |
cex.main |
Magnification used for title relative to the current setting of cex. |
legend |
Logical. When |
d.legend |
Horizontal distance between right border of scatter plots and legend in multiples of title height. |
cex.axis |
Magnification used for axis annotation relative to the current setting of cex. |
nlab.axis |
Approximate number of labels on axes. |
minL.axis |
The minimum length of the abbreviations of factor levels, used to label the axes ticks. |
las |
Orientation of labels on axes. |
border |
Logical. When |
mar , oma
|
Margin and outer margin respectively.
Cf. |
mgp , tcl
|
Cf. |
... |
Additional arguments to |
The idea is similar to gplot.hexbin
. The
hexagons are better suited to reflect the density of points in a plane
than the squares used here. Nevertheless squares are, contrary to
hexagons, invariant to reflexions at the x- and y-axis and
therefore better suited for scatter plot matrices and also for
plotting factors.
The code is based on R function pairs
V1.7.
Maximum number of counts per Pixel found. Additional elements are
returned when verbose == TRUE
.
When you get the error message "Zmax too small! Densiest aereas are out of range!" you must run the function with identical parameters but without specifying zmax. The value returned gives you the minimum value allowed for zmax.
Andreas Ruckstuhl, Rene Locher
## Small numbers of different values are plotted nicer ## when converted to factors AQ <- airquality AQ$Month <- as.factor(AQ$Month) zmax <- ipairs(AQ, pixs=2, main="Air Quality") ipairs(AQ, pixs=2, zmax=zmax, main="Air Quality",border=TRUE) ## example with factors ipairs(iris,pixs=2) ## a really huge dataset ## Not run: if(require(SwissAir)) { data(AirQual) ## low correlation dev.new() ipairs(AirQual[,c("ad.O3","lu.O3","sz.O3")], ztransf=function(x){x[x<1] <- 1; log2(x)}) dev.new() ipairs(AirQual[,c("ad.NO","lu.NO","sz.NO")], ztransf=function(x){x[x<1] <- 1; log2(x)}) ## high correlation Ox <- AirQual[,c("ad.O3","lu.O3","sz.O3")]+ AirQual[,c("ad.NOx","lu.NOx","sz.NOx")]- AirQual[,c("ad.NO","lu.NO","sz.NO")] names(Ox) <- c("ad","lu","sz") dev.new() ipairs(Ox, ztransf=function(x){x[x<1] <- 1; log2(x)}) ## cf. ?AirQual for the explanation of the physical and ## chemical background } else print("Package SwissAir is not available") ## End(Not run)
## Small numbers of different values are plotted nicer ## when converted to factors AQ <- airquality AQ$Month <- as.factor(AQ$Month) zmax <- ipairs(AQ, pixs=2, main="Air Quality") ipairs(AQ, pixs=2, zmax=zmax, main="Air Quality",border=TRUE) ## example with factors ipairs(iris,pixs=2) ## a really huge dataset ## Not run: if(require(SwissAir)) { data(AirQual) ## low correlation dev.new() ipairs(AirQual[,c("ad.O3","lu.O3","sz.O3")], ztransf=function(x){x[x<1] <- 1; log2(x)}) dev.new() ipairs(AirQual[,c("ad.NO","lu.NO","sz.NO")], ztransf=function(x){x[x<1] <- 1; log2(x)}) ## high correlation Ox <- AirQual[,c("ad.O3","lu.O3","sz.O3")]+ AirQual[,c("ad.NOx","lu.NOx","sz.NOx")]- AirQual[,c("ad.NO","lu.NO","sz.NO")] names(Ox) <- c("ad","lu","sz") dev.new() ipairs(Ox, ztransf=function(x){x[x<1] <- 1; log2(x)}) ## cf. ?AirQual for the explanation of the physical and ## chemical background } else print("Package SwissAir is not available") ## End(Not run)
An example of a useful panel function for huge datasets
ipanel.smooth(x, y = NULL, pixs = 1, zmax = NULL, ztransf = function(x) {x}, colramp = IDPcolorRamp, col = "black", lwd = 2, span = 2/3, iter = 3, ...)
ipanel.smooth(x, y = NULL, pixs = 1, zmax = NULL, ztransf = function(x) {x}, colramp = IDPcolorRamp, col = "black", lwd = 2, span = 2/3, iter = 3, ...)
x , y
|
Numeric vectors of the same length. |
pixs |
Size of pixel in x- and y-direction in [mm] on the plotting device. When x and y are numeric, pixels are square. When x and y are factors, pixels are no longer square. The pixels are enlarged in x-direction. |
zmax |
Maximum number of counts per Pixel in the plot. When NULL, the density in the scatter plot is encoded from 0 pixel to maximum number of counts observed. zmax must be equal or larger than maximum number of counts found. |
ztransf |
Function to transform the number of counts per pixel,
which will be mapped by the function in |
colramp |
Color ramp to encode the number of counts within a pixel by color. |
col , lwd
|
Color and line width of the “smoothed curve”. |
span |
the smoother span. This gives the proportion of points in the plot which influence the smooth at each value. Larger values give more smoothness. |
iter |
The number of robustifying iterations which should be performed. Using smaller values of iter will make lowess run faster. |
... |
Other graphical parameters as arguments to the
|
Rene Locher
r.lm <- lm(Sepal.Length~Sepal.Width+Petal.Length+Petal.Width+Species, data = iris) par(mfrow = c(2,2), pty = "s") itermplot(r.lm, se = TRUE, partial.res = TRUE, smooth = ipanel.smooth, lwd.smth = 3, pixs = 2, ask = FALSE) if (require(SwissAir)) { par(mfrow = c(1,1)) dat <- log(AirQual[,c("ad.O3", "ad.WS")]) pairs(dat, panel = ipanel.smooth) } else print("Package SwissAir is not available")
r.lm <- lm(Sepal.Length~Sepal.Width+Petal.Length+Petal.Width+Species, data = iris) par(mfrow = c(2,2), pty = "s") itermplot(r.lm, se = TRUE, partial.res = TRUE, smooth = ipanel.smooth, lwd.smth = 3, pixs = 2, ask = FALSE) if (require(SwissAir)) { par(mfrow = c(1,1)) dat <- log(AirQual[,c("ad.O3", "ad.WS")]) pairs(dat, panel = ipanel.smooth) } else print("Package SwissAir is not available")
Produces an image scatter plot of large datasets where the colors encode the density of the points in the scatter plot. Works also with factors.
iplot(x, y = NULL, pixs = 1, zmax = NULL, ztransf = function(x){x}, colramp = IDPcolorRamp, cex = par("cex"), main = NULL, d.main = 1, cex.main = par("cex.main"), xlab = NULL, ylab = NULL, cex.lab = 1, legend = TRUE, d.legend = 1, cex.axis = par("cex.axis"), nlab.xaxis = 5, nlab.yaxis = 5, minL.axis = 3, las = 1, border = FALSE, oma = c(5,4,1,0)+0.1, mgp = c(2,0.5,0)*cex.axis, tcl = -0.3, ... )
iplot(x, y = NULL, pixs = 1, zmax = NULL, ztransf = function(x){x}, colramp = IDPcolorRamp, cex = par("cex"), main = NULL, d.main = 1, cex.main = par("cex.main"), xlab = NULL, ylab = NULL, cex.lab = 1, legend = TRUE, d.legend = 1, cex.axis = par("cex.axis"), nlab.xaxis = 5, nlab.yaxis = 5, minL.axis = 3, las = 1, border = FALSE, oma = c(5,4,1,0)+0.1, mgp = c(2,0.5,0)*cex.axis, tcl = -0.3, ... )
x , y
|
Coordinates of points whose density is to be plotted. If
|
pixs |
Pixelsize in mm. |
zmax |
Maximum number of counts per pixel in the plot. When
|
ztransf |
Function to transform the number of counts per
pixel, which will be mapped by the function in |
colramp |
Color ramp to encode the number of counts within a pixel. |
cex |
Magnification of text relative to default. |
main |
Title. |
d.main |
Vertical distance between upper border of scatter plots and the title line in multiples of title height. |
cex.main |
Magnification used for title relative to the current setting of cex. |
xlab |
Label for x-axis. |
ylab |
Label for y-axis. |
cex.lab |
Magnification used for text in axis labels relative to the current setting of cex |
legend |
Logical. When |
d.legend |
Horizontal distance between right border of scatter plot and legend in multiples of title height. |
cex.axis |
Magnification used for axis annotation relative to the current setting of cex. |
nlab.xaxis , nlab.yaxis
|
Approximate number of labels on x- and y-axes respectively. |
minL.axis |
The minimum length of the abbreviations of factor levels, used to label the axes ticks. |
las |
Orientation of labels on axes. |
border |
Logical. When |
oma |
Outer margin. Cf. |
mgp , tcl
|
Cf. |
... |
Additional arguments to |
The idea of this plot is similar to
gplot.hexbin
. The
hexagons are better suited to reflect the density of points in a plane
than the squares used here. Nevertheless squares are, contrary to
hexagons, invariant to reflexions at the x- and y-axis and
therefore suited for scatter plot matrices and also for plotting
factors.
Maximum number of counts per Pixel found.
When you get the error message "Zmax too small! Densiest aereas are out of range!" you must run the function again without specifying zmax. The value returned gives you the minimum value allowed for zmax.
Andreas Ruckstuhl, Rene Locher
x <- rnorm(10000) y <- atan(rnorm(10000, 0)) iplot(x, y) iplot(x, pixs = 2) oma <- c(5,5,0,0) iplot(iris[,1:2], pixs = 4, oma = oma) iplot(iris[,"Petal.Width"], iris[,"Species"], pixs = 4, oma = oma) iplot(x = iris[,"Species"], y = iris[,"Petal.Width"], pixs = 10,border = TRUE, xlab = "Species", ylab = "Petal Width", main = "Iris Species and Petal Width", oma = oma) iplot(iris$Species, iris$Petal.Width,pixs = 3, minL.axis = 10, oma = c(3,6,0,0), mgp = c(4, 1, 0), cex.axis = 2, cex.lab = 2, cex.main = 2, main = "Larger fonts")
x <- rnorm(10000) y <- atan(rnorm(10000, 0)) iplot(x, y) iplot(x, pixs = 2) oma <- c(5,5,0,0) iplot(iris[,1:2], pixs = 4, oma = oma) iplot(iris[,"Petal.Width"], iris[,"Species"], pixs = 4, oma = oma) iplot(x = iris[,"Species"], y = iris[,"Petal.Width"], pixs = 10,border = TRUE, xlab = "Species", ylab = "Petal Width", main = "Iris Species and Petal Width", oma = oma) iplot(iris$Species, iris$Petal.Width,pixs = 3, minL.axis = 10, oma = c(3,6,0,0), mgp = c(4, 1, 0), cex.axis = 2, cex.lab = 2, cex.main = 2, main = "Larger fonts")
Plots legend for color ramp.
iplotLegend(colramp, ncol = NULL, cex.axis = par("cex.axis"), border = FALSE, mar = c(0, 0, 0, 3), las = 1, ...)
iplotLegend(colramp, ncol = NULL, cex.axis = par("cex.axis"), border = FALSE, mar = c(0, 0, 0, 3), las = 1, ...)
colramp |
Function defining color ramp,
e.g. |
ncol |
Number of individual colors in color ramp. See details. |
cex.axis |
Magnification to be used for labels. |
border |
Logical. When |
mar |
Margin. See |
las |
Orientation of labels on axis. See |
... |
Additional arguments to |
A color ramp of ncol+1
individual colors is plotted, starting
with the background color (= color 0).
When ncol = NULL
a color ramp of 101 individual colors is
plotted. The color at the bottom is labeled by '0', the color at the
top by 'max'.
Rene Locher
## Not run: par(oma = rep(2, 4)) layout(matrix(c(1, 2), ncol = 2), width = c(lcm(par("csi")*5*2.54), 1), heights = 1) ## End(Not run) iplotLegend(IDPcolorRamp, ncol = 15)
## Not run: par(oma = rep(2, 4)) layout(matrix(c(1, 2), ncol = 2), width = c(lcm(par("csi")*5*2.54), 1), heights = 1) ## End(Not run) iplotLegend(IDPcolorRamp, ncol = 15)
Plots regression terms against their predictors, optionally with standard errors and partial residuals in a density plot.
itermplot(model, data = NULL, envir = environment(formula(model)), partial.resid = FALSE, scale=0, pixs = 1, zmax=NULL, ztransf = function(x) {x}, colramp = IDPcolorRamp, terms = NULL, se = FALSE, xlabs = NULL, ylabs = NULL, main = NULL, col.term = "black", lwd.term = 2, col.se = "gray", lty.se = 2, lwd.se = 1, col.smth = "darkred", lty.smth = 2, lwd.smth = 2, span.smth = 2/3, ask = interactive() && nb.fig < n.tms && .Device != "postscript", use.factor.levels = TRUE, smooth = NULL, ...)
itermplot(model, data = NULL, envir = environment(formula(model)), partial.resid = FALSE, scale=0, pixs = 1, zmax=NULL, ztransf = function(x) {x}, colramp = IDPcolorRamp, terms = NULL, se = FALSE, xlabs = NULL, ylabs = NULL, main = NULL, col.term = "black", lwd.term = 2, col.se = "gray", lty.se = 2, lwd.se = 1, col.smth = "darkred", lty.smth = 2, lwd.smth = 2, span.smth = 2/3, ask = interactive() && nb.fig < n.tms && .Device != "postscript", use.factor.levels = TRUE, smooth = NULL, ...)
model |
Fitted model object |
data |
Data frame in which variables in model can be found |
envir |
Environment in which variables in model can be found |
partial.resid |
Logical; should partial residuals be plotted? |
scale |
A lower limit for the number of units covered by the
limits on the ‘y’ for each plot. The default is |
pixs |
Size of pixel in x- and y-direction in [mm] on the plotting device. When x and y are numeric, pixels are square. When x and y are factors, pixels are no longer square. The pixels are enlarged in x-direction. |
zmax |
Maximum number of counts per pixel in the plot. When NULL, each scatter plot has its individual scale. If a number >= maximum number of counts per pixel is supplied, the scale will be identical for all scatter plots. The maximum number of counts per pixel is delivered by the return value. |
ztransf |
Function to transform the number of counts per pixel.
The user has to make sure that the transformed density lies in the
range [0,zmax], where zmax is any positive number (>=2). For
examples see |
colramp |
Color ramp to encode the number of counts within a pixel by color. |
terms |
Numeric. Which terms to plot (default NULL means all terms) |
se |
Logical. Plot pointwise standard errors? |
xlabs |
Vector of labels for the x axes |
ylabs |
Vector of labels for the y axes |
main |
Logical, or vector of main titles; if TRUE, the model's call is taken as main title, NULL or FALSE mean no titles. |
col.term , lwd.term
|
Color and line width for the “term curve” |
col.se , lty.se , lwd.se
|
Color, line type and line width for the “twice-standard-error curve” when se = TRUE. |
col.smth , lty.smth , lwd.smth
|
Color, line type and line width for the smoothed curve |
span.smth |
Smoothing parameter f for |
ask |
Logical. Should user be asked before each plot? cf.
|
use.factor.levels |
Logical. Should x-axis ticks use factor levels or numbers for factor terms? |
smooth |
NULL or a function with the same arguments as
|
... |
Other graphical parameters |
itermplot
is a modified version of
termplot
of R V2.3.1. Partial residuals are
displayed here as a density plot and is therfore especially suited for
models of huge datasets.
The model object must have a predict method that accepts type=terms,
eg glm in the base package, coxph and survreg in the survival
package.
For the partial.resid=TRUE option it must have a residuals method that
accepts type="partial", which lm
, glm
and
gam
do.
The data argument should rarely be needed, but in some cases termplot may be unable to reconstruct the original data frame. Using na.action=na.exclude makes these problems less likely.
Nothing sensible happens for interaction terms.
Maximum number of counts per pixel found.
Rene Locher
r.lm <- lm(Sepal.Length~Sepal.Width+Petal.Length+Petal.Width+Species, data=iris) par(mfrow=c(2,2),pty="s") itermplot(r.lm, se = TRUE, partial.res=TRUE, lwd.term = 3, lwd.se = 2, pixs = 2) if (require(SwissAir)) { data(AirQual) r.lm <- lm(log(ad.O3)~log(ad.NOx)+ad.T+ad.Td+ad.WS, data=AirQual) par(mfrow=c(2,2),pty="s") itermplot(r.lm, se = TRUE, partial.resid=TRUE, smooth=ipanel.smooth, lwd.smth = 3, pixs = 1, ask=FALSE) } else print("Package SwissAir is not available")
r.lm <- lm(Sepal.Length~Sepal.Width+Petal.Length+Petal.Width+Species, data=iris) par(mfrow=c(2,2),pty="s") itermplot(r.lm, se = TRUE, partial.res=TRUE, lwd.term = 3, lwd.se = 2, pixs = 2) if (require(SwissAir)) { data(AirQual) r.lm <- lm(log(ad.O3)~log(ad.NOx)+ad.T+ad.Td+ad.WS, data=AirQual) par(mfrow=c(2,2),pty="s") itermplot(r.lm, se = TRUE, partial.resid=TRUE, smooth=ipanel.smooth, lwd.smth = 3, pixs = 1, ask=FALSE) } else print("Package SwissAir is not available")
Defines the appearance of the legend of a Rose Plot.
key.control(plot = TRUE, lab = NULL, title = NULL, between = 0)
key.control(plot = TRUE, lab = NULL, title = NULL, between = 0)
plot |
Defines whether legend should be drawn. When
|
lab , title
|
Labels and title of
legend. When |
between |
Distance between label East and left edge of legend in
|
Returns the arguments conveniently packaged up in a list to supply the
arguments for the legend in plot.rose
Rene Locher
key.control()
key.control()
Plot one or more regular time series in multiple figures on one or more pages.
longtsPlot(y1, y2 = NULL, names1 = NULL, names2 = NULL, startP = start(y1)[1], upf = 400, fpp = 4, overlap = 20, x.at = NULL, x.ann = NULL, x.tick = NULL, y1.at = NULL, y1.ann = NULL, y1.tick = NULL, y2.at = NULL, y2.ann = NULL, y2.tick = NULL, nx.ann = 10, ny.ann = 3, cex.ann = par("cex.axis"), xlab = "", y1lab = "", y2lab = "", las = 0, col.y1 = "black", col.y2 = col.y1, cex.lab = par("cex.lab"), y1lim = range(y1, na.rm = TRUE, finite=TRUE), y2lim = range(y2, na.rm = TRUE, finite=TRUE), lty1 = 1, lty2 = 2, lwd1 = 1, lwd2 = lwd1, col1 = NULL, col2 = NULL, leg = TRUE, y1nam.leg = NULL, y2nam.leg = NULL, ncol.leg = NULL, cex.leg = par("cex"), h1 = NULL, h2 = NULL, col.h1 = "gray70", col.h2 = "gray70", main = NULL, cex.main = par("cex.main"), automain = is.null(main), mgp = c(2, 0.7, 0), mar = c(2,3,1,3)+.2, oma = if (automain|!is.null(main)) c(0,0,2,0) else par("oma"), xpd = par("xpd"), cex = par("cex"), type1 = "s", type2 = type1, pch1 = 46, pch2 = pch1, cex.pt1 = 2, cex.pt2 = cex.pt1, slide = FALSE, each.fig = 1, filename = NULL, extension = NULL, filetype = NULL, ...)
longtsPlot(y1, y2 = NULL, names1 = NULL, names2 = NULL, startP = start(y1)[1], upf = 400, fpp = 4, overlap = 20, x.at = NULL, x.ann = NULL, x.tick = NULL, y1.at = NULL, y1.ann = NULL, y1.tick = NULL, y2.at = NULL, y2.ann = NULL, y2.tick = NULL, nx.ann = 10, ny.ann = 3, cex.ann = par("cex.axis"), xlab = "", y1lab = "", y2lab = "", las = 0, col.y1 = "black", col.y2 = col.y1, cex.lab = par("cex.lab"), y1lim = range(y1, na.rm = TRUE, finite=TRUE), y2lim = range(y2, na.rm = TRUE, finite=TRUE), lty1 = 1, lty2 = 2, lwd1 = 1, lwd2 = lwd1, col1 = NULL, col2 = NULL, leg = TRUE, y1nam.leg = NULL, y2nam.leg = NULL, ncol.leg = NULL, cex.leg = par("cex"), h1 = NULL, h2 = NULL, col.h1 = "gray70", col.h2 = "gray70", main = NULL, cex.main = par("cex.main"), automain = is.null(main), mgp = c(2, 0.7, 0), mar = c(2,3,1,3)+.2, oma = if (automain|!is.null(main)) c(0,0,2,0) else par("oma"), xpd = par("xpd"), cex = par("cex"), type1 = "s", type2 = type1, pch1 = 46, pch2 = pch1, cex.pt1 = 2, cex.pt2 = cex.pt1, slide = FALSE, each.fig = 1, filename = NULL, extension = NULL, filetype = NULL, ...)
y1 , y2
|
Regular time series, time series matrices or ordinary
vectors, dataframes or matrices with values corresponding to regular
time intervals. Corresponding axes are on the left (for |
names1 , names2
|
Names for time series used for legend. |
startP |
Start time of plot. |
upf |
Number of time units plottet per figure. |
fpp |
Number of figures per page (screen). |
overlap |
Length of time series on the right end of the figures which is identical with the left start of the next figure. |
x.at |
Time points at which long ticks on x-axis and annotations are set. |
x.ann |
Time annotations (character vector) for long ticks on x-axis |
x.tick |
Time points at which short ticks are set on x-axis. If Null, no short ticks are set. |
y1.at , y1.ann , y1.tick , y2.at , y2.ann , y2.tick
|
Arguments starting with 'y1' ('y2') correspond to arguments for left (right) axis. For details see arguments for x-axis. |
nx.ann , ny.ann
|
Approximate number of annotations on x- and y-axes, respectively |
cex.ann |
The magnification to be used for axis annotation relative to the current setting of cex. |
xlab |
Label for x-axis. |
y1lab , y2lab
|
Labels for y-axes on the left and on the right end of the figure. |
las |
Cf. |
col.y1 , col.y2
|
Colors for left and right axis respectively. |
cex.lab |
cex of labels. |
y1lim , y2lim
|
Limits for left and right axis respectively. |
lty1 , lty2
|
Vector of line types for each time series, possibly recycled. |
lwd1 , lwd2
|
Vector of line widths for each time series, possibly recycled. |
col1 , col2
|
Vector of color for each time series, possibly recycled. |
leg |
Logical. When TRUE, legend is drawn. |
y1nam.leg , y2nam.leg
|
Name of y1- and y2-axis in legend. |
ncol.leg |
Number of columns in legend. |
cex.leg |
cex for legend. |
h1 , h2
|
Vector of y-positions of horizontal lines in the coordinate systems represented by the left and the right axis respectively. |
col.h1 , col.h2
|
Vector of colors for horizontal lines. |
main |
Title of plot. |
cex.main |
cex of title. |
automain |
Logical. When |
mgp , mar , oma
|
Cf. |
xpd |
Define whether data points are clipped to the plot region
(=FALSE) or not (=TRUE). Horizontal lines, defined by |
cex |
Cf. |
type1 , type2
|
For plotting lines or
points. Cf. |
pch1 , pch2 , cex.pt1 , cex.pt2
|
Plotting symbols and there sizes when 'type1' or 'type2' = "p" |
slide |
Logical. When |
each.fig |
For |
filename |
When |
extension |
The extension is defined automatically on windows systems and must be defined manually on the other systems. |
filetype |
On Windows:
The type of plot, Windows metafile, PNG, JPEG,
BMP (Windows bitmap format), TIFF, PostScript or PDF.
Defaults to Windows meta file, |
... |
Additional arguments to
|
For longer time-series, it is sometimes important to spread several
time-series plots over several subplots or even over several pages
with several subplots in each. Moreover, these series have often
different ranges, frequencies and start times. There is sometimes also
the need of a more flexible annotation of axes than plot.ts
provides. longtsPlot
provides the user with all these features
for one or two matrices or regular time series (time series matrices).
One or more pages of time series plots are drawn on the current graphic device and, optionally, saved in one or more files.
Rene Locher
## sunspots, y-axis only on the left data(sunspots) longtsPlot(sunspots,upf=ceiling((end(sunspots)-start(sunspots))[1]/5)) ## air quality (left axis) and meteo data (right axis) ## use xpd=TRUE for time series with rare but large values if (require(SwissAir)) { data(AirQual) st <- 6.5*30*48 x.at <- seq(st,nrow(AirQual),48) longtsPlot(y1=AirQual[,c("ad.O3","ad.NOx")], y2 = AirQual$ad.T, names1=c("O3","NOx"),names2 = "Temp", startP = st, upf=7*48, x.at = x.at, x.ann = substr(AirQual$start,1,6)[x.at], x.tick = seq(st,nrow(AirQual),12), y1.at = c(0,100), y1.tick = seq(0,150,50), y2.at = c(10,30), y2.tick = seq(10,30,10), y1lab="[ppb]", y2lab="[C]", y1lim = c(0,100), y2lim = c(10,30), xpd=TRUE, col2 = "red", type1 = "l") } ## Two time series with different frequencies and start times ## on the same figures set.seed(13) len <- 4*6*400 x <- sin((1:len)/200*pi) d <- sin(cumsum(1+ rpois(len, lambda= 2.5))) y1 <- ts(10*x,start=0,frequency=6)+d*rnorm(len) y2 <- ts(100*x,start=100,frequency=13)+10*rnorm(len) longtsPlot(y1,y2) ## plot your own legend longtsPlot(sunspots, upf = ceiling((end(sunspots)-start(sunspots))[1]/5), fpp = 1, leg = FALSE) legend(1750, 260, legend = "Monthly Sunspot Numbers", col = "blue", lwd = 1, bty = "n")
## sunspots, y-axis only on the left data(sunspots) longtsPlot(sunspots,upf=ceiling((end(sunspots)-start(sunspots))[1]/5)) ## air quality (left axis) and meteo data (right axis) ## use xpd=TRUE for time series with rare but large values if (require(SwissAir)) { data(AirQual) st <- 6.5*30*48 x.at <- seq(st,nrow(AirQual),48) longtsPlot(y1=AirQual[,c("ad.O3","ad.NOx")], y2 = AirQual$ad.T, names1=c("O3","NOx"),names2 = "Temp", startP = st, upf=7*48, x.at = x.at, x.ann = substr(AirQual$start,1,6)[x.at], x.tick = seq(st,nrow(AirQual),12), y1.at = c(0,100), y1.tick = seq(0,150,50), y2.at = c(10,30), y2.tick = seq(10,30,10), y1lab="[ppb]", y2lab="[C]", y1lim = c(0,100), y2lim = c(10,30), xpd=TRUE, col2 = "red", type1 = "l") } ## Two time series with different frequencies and start times ## on the same figures set.seed(13) len <- 4*6*400 x <- sin((1:len)/200*pi) d <- sin(cumsum(1+ rpois(len, lambda= 2.5))) y1 <- ts(10*x,start=0,frequency=6)+d*rnorm(len) y2 <- ts(100*x,start=100,frequency=13)+10*rnorm(len) longtsPlot(y1,y2) ## plot your own legend longtsPlot(sunspots, upf = ceiling((end(sunspots)-start(sunspots))[1]/5), fpp = 1, leg = FALSE) legend(1750, 260, legend = "Monthly Sunspot Numbers", col = "blue", lwd = 1, bty = "n")
The spectrum was taken from a sample of sheep blood. The instrument used was a so called SELDI TOF (Surface Enhanced Laser Desorption Ionisation, Time Of Flight) Mass Spectrometer.
data(MS)
data(MS)
A data frame with 45213 observations on the following 2 variables.
mz
mass / charge
I
Intensity
The measured masses lie between m/z=1000 and 200000. The intensities are raw output. Neither smoothing nor background subtraction was applied to the spectrum.
Medical research project.
data(MS) MS1 <- log10(MS[MS$mz>12000&MS$mz<1e5,]) P <- peaks(MS1, minPH=0.025, minPW=0.0015) plot(MS1, ty="l", xlim=c(4.15,5)) points(P,col="red")
data(MS) MS1 <- log10(MS[MS$mz>12000&MS$mz<1e5,]) P <- peaks(MS1, minPH=0.025, minPW=0.0015) plot(MS1, ty="l", xlim=c(4.15,5)) points(P,col="red")
Omits observations with values which a not regular (=Not a Regular Value) when object is a vector, a factor, a data.frame or a matrix.
NaRV.omit(x)
NaRV.omit(x)
x |
|
Irregular values are defined as NA
, NaN
, Inf
and
-Inf
Values in numerics and NA
in factors and
characters.
Returns objects of class
vector, factor, data.frame or matrix
in the same way as na.omit
does. Returns all other
objects unchanged and prints a warning.
Rene Locher
M <- matrix(c(NA,1:7,NA),nrow=3) M NaRV.omit(M) DF <- iris[sample(1:nrow(iris),12),] DF[1,1] <- NA DF[10,5] <- NA row.names(DF) <- 1:12 DF NaRV.omit(DF) NaRV.omit(c(NA,1:10,NA)) fac <- factor(c(NA,sample(c(1:9)))) NaRV.omit(fac) fac <- factor(c(NA,sample(c(1:9))),exclude=NULL) fac NaRV.omit(fac)
M <- matrix(c(NA,1:7,NA),nrow=3) M NaRV.omit(M) DF <- iris[sample(1:nrow(iris),12),] DF[1,1] <- NA DF[10,5] <- NA row.names(DF) <- 1:12 DF NaRV.omit(DF) NaRV.omit(c(NA,1:10,NA)) fac <- factor(c(NA,sample(c(1:9)))) NaRV.omit(fac) fac <- factor(c(NA,sample(c(1:9))),exclude=NULL) fac NaRV.omit(fac)
Sets NAs in logical vectors and matrices to FALSE. This is especially
useful for conditional selections of data when the variables the
condition is based on contain NA
s.
ok(x)
ok(x)
x |
Logical vector or matrix |
Logical vector or matrix, containing no NA
s.
Rene Locher
ok(c(FALSE,TRUE,NA,TRUE))
ok(c(FALSE,TRUE,NA,TRUE))
Returns position, signal height and approximate width at half maximum peak height.
peaks(x, y = NULL, minPH, minPW, thr, stepF = 0.49)
peaks(x, y = NULL, minPH, minPW, thr, stepF = 0.49)
x , y
|
Position and height of signal. Any reasonable way of
defining the coordinates is acceptable. See function
|
minPH |
Mimimum height of peak to be reported. |
minPW |
Minimum width of peak at half maximum to be reported. |
thr |
Threshold below which the signal is not processed. |
stepF |
|
The function is especially useful for signals in which both very broad and very narrow peaks are of interest. The peaks may lie very close to each other or might even be superpositioned on top of each other, e.g. peaks on broader shoulders. The algorithm is also very useful when the resolution of the signal is poor and the noise is small.
The function is looking for peaks without any preceding baseline substraction or smoothing, which could distort the spectrum.
The selection criteria minPH
and minPW
and the values
for the calculated peak widths are only approximate.
dataframe consisting of
x |
Position of peak |
y |
Signal height |
w |
Approximate width at half maximum of peak |
In the function, the main selection criterium for the peaks is the height of the peaks, the second optional criterium is the width of the peaks.
Rene Locher
n <- 200 freq <- 1:n theory <- sin(freq/n*4*pi)*cos(freq/n*3*pi) spec <- theory + 0.1*rnorm(n) plot(spec,type="b") lines(theory,lwd=2) pts <- peaks(spec, minPH=0.7) points(pts,col="red",cex=1.2, pch=20) ## peaks after smoothing the spectrum spec.sm <- loess.smooth(freq, spec, span=0.2, degree = 2, evaluation = 100) lines(spec.sm$x, spec.sm$y, col="steelblue", lwd=2) pts <- peaks(spec.sm, minPH=0.4) points(pts,col="green",cex=1.2,pch=20) ## Analyses of Mass Spectrum between 12000 and 100'000 ## without smoothing, without baseline substraction data(MS) MS1 <- log10(MS[MS$mz>12000&MS$mz<1e5,]) P <- peaks(MS1, minPH=0.02, minPW=0.001) plot(MS1, type="l", xlab="log10(mz)", ylab="log10(I)") points(P,col="blue",cex=1.6)
n <- 200 freq <- 1:n theory <- sin(freq/n*4*pi)*cos(freq/n*3*pi) spec <- theory + 0.1*rnorm(n) plot(spec,type="b") lines(theory,lwd=2) pts <- peaks(spec, minPH=0.7) points(pts,col="red",cex=1.2, pch=20) ## peaks after smoothing the spectrum spec.sm <- loess.smooth(freq, spec, span=0.2, degree = 2, evaluation = 100) lines(spec.sm$x, spec.sm$y, col="steelblue", lwd=2) pts <- peaks(spec.sm, minPH=0.4) points(pts,col="green",cex=1.2,pch=20) ## Analyses of Mass Spectrum between 12000 and 100'000 ## without smoothing, without baseline substraction data(MS) MS1 <- log10(MS[MS$mz>12000&MS$mz<1e5,]) P <- peaks(MS1, minPH=0.02, minPW=0.001) plot(MS1, type="l", xlab="log10(mz)", ylab="log10(I)") points(P,col="blue",cex=1.6)
Describes plot method for class "rose"
## S4 method for signature 'rose,missing' plot( x, transf = function(x) sqrt(x), subset.col = NULL, warn = TRUE, general = general.control(), grid = grid.control(), title = title.control(), key = key.control())
## S4 method for signature 'rose,missing' plot( x, transf = function(x) sqrt(x), subset.col = NULL, warn = TRUE, general = general.control(), grid = grid.control(), title = title.control(), key = key.control())
x |
Object |
transf |
Transformation function for |
subset.col |
Display only a subset of the columns of
|
warn |
Logical. If |
general |
Settings for general appearance of plot, defined in
|
grid |
Settings for appearance of guiding elements of rose such
as circles, rays and labels, defined in |
title |
Settings for title, defined in
|
key |
Settings for appearance of the legend, defined in
|
This function appeals especially to environmental specialists who
often have response variables, which depend from cyclic variables like
the direction of wind, the hour of the day, the month etc. All these
variables are displayed usually clockwise,
starting with 0 in the north (12 o' clock). We call this
kind of coordinates 'clock coordinates', to distinct them from the
polar coordinates as used in mathematical context. The
rose
object is displayed as the time on a clock,
measuring the angle defined in slot cyclVar
in the clockwise
direction from the north.
The eye takes the area of a graphical object as a measure of its
size. This is why the default transformation of x@rho
is
chosen to be the square root. For equal distance roses use the
transformation function function(x) x
.
All labels, titles and line sizes are defined in multiples of cex.
This graphic function is based on package grid:
Viewport vp.rose
which was used to draw the rose and viewport
vp.key
which was used to draw the key may be addressed by
pushviewport()
after having drawn the figure.
No value returned
The function is designed to use the area on the active viewport in an
optimal way, but the plot is not scalable after having been drawn.
Furthermore this function is still experimental so that some features
may change in future versions.
You will find another nice example for this plot method in AirQual
Rene Locher
hour <- rep(0:23,100) WD <- c(rnorm(24*90, mean=sample(c(190,220,50),24*90, replace = TRUE),sd=10), rnorm(24*10, mean=360, sd=180))%%360 dat <- data.frame(A = (2*cos((hour+6)/6*pi)+ 2*cos((WD+60)/180*pi)+rnorm(24*100,4))^2, B = (2*cos((hour+4)/6*pi)+rnorm(24*100,1,8))^2) dat$B[dat$B>1000] <- 1000 ## two different response variables, scalar summary function mean.dayrose <- rose(dat[,c("A","B")], cyclVar = hour, n.cyclVar = 24, circle = 24, FUN=mean, na.rm=TRUE) ## one response variable, vector summary function quant.windrose <- rose(dat$A, cyclVar = WD, n.cyclVar = 16, circle = 360, FUN=quantile, na.rm=TRUE) ## one response variable, second (non cyclic) explanatory variable, ## scalar summary function windrose <- rose(dat[,c("A")], cyclVar = WD, n.cyclVar=8, circle = 360, cut = dat$B, breaks = c(0,10,100,1000), include.lowest = TRUE, dig.lab = 4, FUN = function(x) sum(!is.na(x))) grid::grid.newpage() plot(mean.dayrose, general = general.control( mar = rep(1,4), stacked = FALSE, lwd = 3, lty = c(1:2)), grid = grid.control( circ.n = 2, circ.sub.n = 2, circ.lwd = 2, circ.sub.col = "black", ray.n = 12, cyclVar.lab = seq(0,by=2,to=22)), title = title.control(text = "unstacked dayrose"), key = key.control(title = "Mean", between = 0)) grid::grid.newpage() plot(quant.windrose) grid::grid.newpage() plot(windrose, general = general.control( stacked = TRUE, lwd = 3), grid = grid.control( circ.n = 2, circ.sub.n = 2), title = title.control( text = "Stacked windrose:\nCounts of A-Values"), key = key.control(title = "Value of B")) if (require(SwissAir)){ data(AirQual) dat <- data.frame(month =as.numeric(substr(AirQual$start,4,5)), hour = as.numeric(substr(AirQual$start,12,13)), WD = AirQual$ad.WD, NOx = AirQual$ad.NOx, ## NO2 = AirQual$ad.NOx-AirQual$ad.NO, ## NO = AirQual$ad.NO, O3 = AirQual$ad.O3, Ox = AirQual$ad.O3+AirQual$ad.NOx-AirQual$ad.NO) ## Windrose windrose <- rose(dat$WD, cyclVar = dat$WD, n.cyclVar = 32, circle = 360, FUN = function(x) sum(!is.na(x))) grid::grid.newpage() plot(windrose, general = general.control(lwd = 2), grid = grid.control(circ.n = 2, circ.sub.n = 2)) ## median of concentrations as a function of daytime ## from May to September med.dayrose <- rose(dat[,c("NOx","O3","Ox")], subset= dat$month>4 & dat$month<10, cyclVar=dat$hour, n.cyclVar=24, circle=24, FUN=median, na.rm=TRUE) ## line type version of rose grid::grid.newpage() plot(med.dayrose, general = general.control(lwd=2, type="l"), grid = grid.control(ray.n = 12, circ.n =2, circ.sub.n = 2, cyclVar.lab = seq(0,by=2,to=22)), title = title.control(text = "Day Rose of Medians\nduring summer")) ## quantiles of concentrations as a function of daytime ## from May to September quant.dayrose <- rose(dat$NOx, subset= dat$month>4 & dat$month<10, cyclVar=dat$hour, n.cyclVar=24, circle=24, FUN=quantile, na.rm=TRUE) grid::grid.newpage() plot(quant.dayrose, general = general.control(mar = c(0.3, 0.3, 0.3, 2), lwd = 2), grid = grid.control(ray.n = 12, cyclVar.lab = seq(0,by=2,to=22)), title = title.control(text = "Concentration of NOx [ppb]\nduring summer"), key = key.control(title = "Quantiles")) } else print("Package SwissAir is not available")
hour <- rep(0:23,100) WD <- c(rnorm(24*90, mean=sample(c(190,220,50),24*90, replace = TRUE),sd=10), rnorm(24*10, mean=360, sd=180))%%360 dat <- data.frame(A = (2*cos((hour+6)/6*pi)+ 2*cos((WD+60)/180*pi)+rnorm(24*100,4))^2, B = (2*cos((hour+4)/6*pi)+rnorm(24*100,1,8))^2) dat$B[dat$B>1000] <- 1000 ## two different response variables, scalar summary function mean.dayrose <- rose(dat[,c("A","B")], cyclVar = hour, n.cyclVar = 24, circle = 24, FUN=mean, na.rm=TRUE) ## one response variable, vector summary function quant.windrose <- rose(dat$A, cyclVar = WD, n.cyclVar = 16, circle = 360, FUN=quantile, na.rm=TRUE) ## one response variable, second (non cyclic) explanatory variable, ## scalar summary function windrose <- rose(dat[,c("A")], cyclVar = WD, n.cyclVar=8, circle = 360, cut = dat$B, breaks = c(0,10,100,1000), include.lowest = TRUE, dig.lab = 4, FUN = function(x) sum(!is.na(x))) grid::grid.newpage() plot(mean.dayrose, general = general.control( mar = rep(1,4), stacked = FALSE, lwd = 3, lty = c(1:2)), grid = grid.control( circ.n = 2, circ.sub.n = 2, circ.lwd = 2, circ.sub.col = "black", ray.n = 12, cyclVar.lab = seq(0,by=2,to=22)), title = title.control(text = "unstacked dayrose"), key = key.control(title = "Mean", between = 0)) grid::grid.newpage() plot(quant.windrose) grid::grid.newpage() plot(windrose, general = general.control( stacked = TRUE, lwd = 3), grid = grid.control( circ.n = 2, circ.sub.n = 2), title = title.control( text = "Stacked windrose:\nCounts of A-Values"), key = key.control(title = "Value of B")) if (require(SwissAir)){ data(AirQual) dat <- data.frame(month =as.numeric(substr(AirQual$start,4,5)), hour = as.numeric(substr(AirQual$start,12,13)), WD = AirQual$ad.WD, NOx = AirQual$ad.NOx, ## NO2 = AirQual$ad.NOx-AirQual$ad.NO, ## NO = AirQual$ad.NO, O3 = AirQual$ad.O3, Ox = AirQual$ad.O3+AirQual$ad.NOx-AirQual$ad.NO) ## Windrose windrose <- rose(dat$WD, cyclVar = dat$WD, n.cyclVar = 32, circle = 360, FUN = function(x) sum(!is.na(x))) grid::grid.newpage() plot(windrose, general = general.control(lwd = 2), grid = grid.control(circ.n = 2, circ.sub.n = 2)) ## median of concentrations as a function of daytime ## from May to September med.dayrose <- rose(dat[,c("NOx","O3","Ox")], subset= dat$month>4 & dat$month<10, cyclVar=dat$hour, n.cyclVar=24, circle=24, FUN=median, na.rm=TRUE) ## line type version of rose grid::grid.newpage() plot(med.dayrose, general = general.control(lwd=2, type="l"), grid = grid.control(ray.n = 12, circ.n =2, circ.sub.n = 2, cyclVar.lab = seq(0,by=2,to=22)), title = title.control(text = "Day Rose of Medians\nduring summer")) ## quantiles of concentrations as a function of daytime ## from May to September quant.dayrose <- rose(dat$NOx, subset= dat$month>4 & dat$month<10, cyclVar=dat$hour, n.cyclVar=24, circle=24, FUN=quantile, na.rm=TRUE) grid::grid.newpage() plot(quant.dayrose, general = general.control(mar = c(0.3, 0.3, 0.3, 2), lwd = 2), grid = grid.control(ray.n = 12, cyclVar.lab = seq(0,by=2,to=22)), title = title.control(text = "Concentration of NOx [ppb]\nduring summer"), key = key.control(title = "Quantiles")) } else print("Package SwissAir is not available")
Convenient xyplot with Colored Background. Background of margin may be chosen independently from background in plot region.
poster.plot(x, y = NULL, type = "p", col = col.fg, col.axis = col.fg, col.lab = col.fg, col.fg = "blue", col.bg = "lavender", col.box = "cornsilk", xlim = NULL, ylim = NULL, xlab = "", ylab = "", main = "", cex = 1.2, axes = TRUE, ...)
poster.plot(x, y = NULL, type = "p", col = col.fg, col.axis = col.fg, col.lab = col.fg, col.fg = "blue", col.bg = "lavender", col.box = "cornsilk", xlim = NULL, ylim = NULL, xlab = "", ylab = "", main = "", cex = 1.2, axes = TRUE, ...)
x |
A vector, data.frame or matrix. When x is data.frame or matrix only first two columns are used. |
y |
A vector or |
type |
See Argument |
col |
Color of points. If |
col.axis |
Color of axis. |
col.lab |
Color of labels on axis. |
col.fg |
Color of foreground. |
col.bg |
Color of background outside of figure. |
col.box |
Color of background inside of figure |
xlim |
Limits of x-axis. |
ylim |
Limits of y-axis |
xlab |
Label of x-axis |
ylab |
Label of y-axis |
main |
Titel. |
cex |
Size of characters. |
axes |
Should axis be plotted? |
... |
Additional arguments to |
Side effect: par
options will remain changed so that other
graphic elements can be added comfortably.
Andreas Ruckstuhl, refined by Rene Locher
poster.plot(iris[,1],iris[,2], xlab="Sepal.Length", ylab="Sepal.Width") poster.plot(iris[,1], col="red", col.box="grey95", ylab="Sepal.Length") ## plotting lines n <- 200 freq <- 1:n y <- sin(freq/n*4*pi)*cos(freq/n*3*pi) + 0.1*rnorm(n) poster.plot(y,col.fg="grey30",type="l")
poster.plot(iris[,1],iris[,2], xlab="Sepal.Length", ylab="Sepal.Width") poster.plot(iris[,1], col="red", col.box="grey95", ylab="Sepal.Length") ## plotting lines n <- 200 freq <- 1:n y <- sin(freq/n*4*pi)*cos(freq/n*3*pi) + 0.1*rnorm(n) poster.plot(y,col.fg="grey30",type="l")
Robust fitting of local regression models for estimating a baseline or a background signal
rfbaseline(x, y, span = 2/3, NoXP = NULL, maxit = c(2, 2), b = 3.5, weight = NULL, Scale = function(r) median(abs(r))/0.6745, delta = NULL, SORT = TRUE, DOT = FALSE, init = NULL)
rfbaseline(x, y, span = 2/3, NoXP = NULL, maxit = c(2, 2), b = 3.5, weight = NULL, Scale = function(r) median(abs(r))/0.6745, delta = NULL, SORT = TRUE, DOT = FALSE, init = NULL)
x , y
|
Abscissa and ordinate of the points on the scatterplot. |
span |
Specifies the amount of smoothing; span is the fraction of points used to compute each fitted value; as span increases the output becomes smoother. |
NoXP |
Another way of specifying the amount of smoothing; NoXP is the Number of X Points used to compute each fitted value; it must be larger than 3. |
maxit |
The number of iterations in the robust fit; if maxit=c(0,0), the nonrobust fit is returned; the first entry specifies the number of iterations using an asymmetric biweight function, whereas the second entry specifies the number of iterations using the usual (symmetric) biweight function. |
b |
Tuning constant in the biweight function. |
weight |
Optional weights to be given to individual observations. |
Scale |
function specifying how to calculate the scale of the residuals. |
delta |
Nonnegative parameter which may be used to save
computation. By default, if |
SORT |
Boolean variable indicating whether x data must be sorted. Change it only when the x are sorted and you want to safe computer time. |
DOT |
If TRUE disregard outliers totally; that is, observations with weight 0 are disregarded even when the neighbourhood is determined. |
init |
Values of an initial fit. |
List containing components
x |
Sorted input vector x with duplicate points removed |
y |
Corresponding input vector y |
fit |
Fitted values at x |
rw |
Robust weights of (x,y)-Points used in last iteration of fit |
scale |
Scale used in last iteration of fit |
Andreas Ruckstuhl
Ruckstuhl, Andreas F., Matthew P. Jacobson, Robert W. Field and James A. Dodd (2001); Baseline Subtraction Using Robust Local Regression Estimation; Journal of Quantitative Spectroscopy and Radiative Transfer 68: 179 – 193
Ruckstuhl, Andreas F., et al.; Estimation of background concentrations of atmospheric trace gases using robust local regression; to be published
data(MS) MS1 <- log10(MS[MS$mz>12000&MS$mz<1e5,]) MS1.rfb2 <- rfbaseline(x=MS1$mz, y=MS1$I, NoXP=2200, maxit=c(5,0)) plot(x=MS1$mz, y=MS1$I, type="l", xlab="log(mass/charge)", ylab="log(intensity)") lines(MS1.rfb2$x, MS1.rfb2$fit, col="orange", lwd=3) MS1.rfb3 <- rfbaseline(x=MS1$mz, y=MS1$I, NoXP=1100, maxit=c(5,0), DOT=TRUE, Scale=function(x) mad(x, center=0)) plot(x=MS1$mz, y=MS1$I, type="l", xlab="log(mass/charge)", ylab="log(intensity)") lines(MS1.rfb3$x, MS1.rfb3$fit, col="orange", lwd=3) ## 'delta=0' needs much more computer time ## Not run: MS1.rfb4 <- rfbaseline(x=MS1$mz, y=MS1$I, NoXP=2200, delta=0, maxit=c(5,0)) plot(x=MS1$mz, y=MS1$I,ty="l", xlab="log(mass/charge)", ylab="log(intensity)") lines(MS1.rfb4$x, MS1.rfb4$fit, col="orange", lwd=3) ## End(Not run)
data(MS) MS1 <- log10(MS[MS$mz>12000&MS$mz<1e5,]) MS1.rfb2 <- rfbaseline(x=MS1$mz, y=MS1$I, NoXP=2200, maxit=c(5,0)) plot(x=MS1$mz, y=MS1$I, type="l", xlab="log(mass/charge)", ylab="log(intensity)") lines(MS1.rfb2$x, MS1.rfb2$fit, col="orange", lwd=3) MS1.rfb3 <- rfbaseline(x=MS1$mz, y=MS1$I, NoXP=1100, maxit=c(5,0), DOT=TRUE, Scale=function(x) mad(x, center=0)) plot(x=MS1$mz, y=MS1$I, type="l", xlab="log(mass/charge)", ylab="log(intensity)") lines(MS1.rfb3$x, MS1.rfb3$fit, col="orange", lwd=3) ## 'delta=0' needs much more computer time ## Not run: MS1.rfb4 <- rfbaseline(x=MS1$mz, y=MS1$I, NoXP=2200, delta=0, maxit=c(5,0)) plot(x=MS1$mz, y=MS1$I,ty="l", xlab="log(mass/charge)", ylab="log(intensity)") lines(MS1.rfb4$x, MS1.rfb4$fit, col="orange", lwd=3) ## End(Not run)
Estimation of the scale parameter based on data smaller than its first mode. Mainly used in rfbaseline.
rfbaselineScale(r)
rfbaselineScale(r)
r |
residuals |
Estimated scale.
Andreas Ruckstuhl
See also mad
rose
splits data into subsets according to one or two
grouping elements, computes summary statistics for each, and returns
the result in a rose object.
rose(x, subset = NULL, cyclVar = NULL, circle = NULL, n.cyclVar = 8, cut = NULL, labels = NULL, breaks = NULL, include.lowest = FALSE, right = TRUE, dig.lab = 2, warn = TRUE, FUN = mean, ...)
rose(x, subset = NULL, cyclVar = NULL, circle = NULL, n.cyclVar = 8, cut = NULL, labels = NULL, breaks = NULL, include.lowest = FALSE, right = TRUE, dig.lab = 2, warn = TRUE, FUN = mean, ...)
x |
Vector, data frame or matrix containing the response. |
subset |
An optional vector specifying a subset of observations to be used in the aggregating process. |
cyclVar |
Cyclic variable as first grouping
element. |
circle |
Defines the value of a full circle with no default. |
n.cyclVar |
Defines the number of equally spaced intervals of the cyclic variable, into which the data are split. The first interval is labeled with 0 and is always centered around 0. |
cut |
Vector of numerics, logicals or factors as second grouping
elements. Its length is equal to the number of rows in
|
labels |
Labels for the corresponding intervals. When cut is a logical, labels has to be named in the order: FALSE, TRUE. |
breaks , include.lowest , right , dig.lab
|
These arguments are
only active when |
warn |
Logical, indicating if warnings should be issued
for NAs in |
FUN |
Summary function, returning a scalar or vector. |
... |
Additional arguments for summary function. |
The first grouping element, cyclVar
, for the summary statistics
must be circular and numeric. The second grouping element, cut
,
can be numeric, logical or a factor.
Not all combinations of arguments are allowed:
Argument cut
can only be defined when summary consists of a
scalar and x
consists of 1 column.
When x
contains only one column and cut
is not
defined, the summary function may also be a vector with the
restriction, that the summary of each subset, defined by the cyclic
variable, must have the same number of elements.
When x
is a data frame or matrix with more than 1 column,
the summary function must be scalar.
Object of class rose
Rene Locher
rose-class, plot.rose, cart2clock
,
clock2cart
## artificial example: ## concentration of A and B as function of ## hour of day (hour) and wind direction (WD) hour <- rep(0:23,100) dat <- data.frame(hour = hour, A = (2*cos((hour+6)/6*pi)+rnorm(24*100,1))^2, B = (2*cos((hour+4)/6*pi)+rnorm(24*100,1,2))^2, WD = rnorm(24*100, mean=sample(c(190,220,50),24*100, replace = TRUE), sd=30)%%360) ## two different responses, scalar summary function mean.windrose <- rose(dat[,c("A","B")], cyclVar=dat$WD, circle=360, FUN=mean, na.rm=TRUE) mean.windrose ## one response, vectorial summary function quant.dayrose <- rose(dat$A, cyclVar=dat$hour, n.cyclVar=24, circle=24, FUN=quantile, na.rm=TRUE) quant.dayrose mean.windroseB <- rose(dat[,c("A")], cyclVar=dat$WD, circle=360, cut=dat$B, breaks=c(0,30,100), dig.lab=3, FUN=mean, na.rm=TRUE) mean.windroseB
## artificial example: ## concentration of A and B as function of ## hour of day (hour) and wind direction (WD) hour <- rep(0:23,100) dat <- data.frame(hour = hour, A = (2*cos((hour+6)/6*pi)+rnorm(24*100,1))^2, B = (2*cos((hour+4)/6*pi)+rnorm(24*100,1,2))^2, WD = rnorm(24*100, mean=sample(c(190,220,50),24*100, replace = TRUE), sd=30)%%360) ## two different responses, scalar summary function mean.windrose <- rose(dat[,c("A","B")], cyclVar=dat$WD, circle=360, FUN=mean, na.rm=TRUE) mean.windrose ## one response, vectorial summary function quant.dayrose <- rose(dat$A, cyclVar=dat$hour, n.cyclVar=24, circle=24, FUN=quantile, na.rm=TRUE) quant.dayrose mean.windroseB <- rose(dat[,c("A")], cyclVar=dat$WD, circle=360, cut=dat$B, breaks=c(0,30,100), dig.lab=3, FUN=mean, na.rm=TRUE) mean.windroseB
Summary statistics of cyclic data.
Objects can be created by calls of the form
rose(x, cyclVar = NULL, circle = NULL, n.cyclVar = 8,
cut = NULL, breaks = NULL,
labels = NULL, dig.lab = 2,
include.lowest = FALSE, subset = NULL,
na.warning = TRUE, FUN = mean, ...)
rho
:Object of class matrix
. rho[i,]
contains the summary values of all data within the interval
defined by the cyclic Variable cyclVar[i]
. Column and row
names are mandatory. The different columns of rho
correspond to different responses when the summary statistics is a
scalar or to the different elements of a vector summary of
one response or to the different subsets of the second
grouping element.
cyclVar
:Object of class numeric
containing
the center of the interval of the cyclic variable. The values are
sorted by increasing values, are unique and cannot contain NA
values.
circle
:Scalar of class numeric
, defining the
full circle.
Rene Locher
For the details of how to create and plot a rose
object
see rose
and plot.rose
.
Displays colors produced by a color vector col
and labels them by the
corresponding number of the element of col
.
showColors(col = IDPcolorRamp(20), ntm = min(length(col), 20), border = TRUE, mar = rep(0,4))
showColors(col = IDPcolorRamp(20), ntm = min(length(col), 20), border = TRUE, mar = rep(0,4))
col |
Color vector |
ntm |
Approximate number of labels printed |
border |
Shall border be drawn between the colors in the legend:
|
mar |
Margin. cf |
Rene Locher
showColors(IDPcolorRamp(5)) showColors(IDPcolorRamp(200),border=FALSE) showColors(IDPcolorRamp(200),border=FALSE,ntm=5) showColors(IDPcolorRamp(4, colInt = data.frame( h = c(0.47, 0.28, 0.22, 0.2, 0.00), s = c(0.3, 0.55, 0.75, 0.75, 0.75), v = c(1, 1, 1, 1, 1)), fr = c(0.2,0.2,0.2)) ,border=FALSE) showColors(IDPcolorRamp(200, t(col2hsv(c("darkviolet","blue", "green","yellow","red"))), fr=rep(0.25,3)),border=FALSE)
showColors(IDPcolorRamp(5)) showColors(IDPcolorRamp(200),border=FALSE) showColors(IDPcolorRamp(200),border=FALSE,ntm=5) showColors(IDPcolorRamp(4, colInt = data.frame( h = c(0.47, 0.28, 0.22, 0.2, 0.00), s = c(0.3, 0.55, 0.75, 0.75, 0.75), v = c(1, 1, 1, 1, 1)), fr = c(0.2,0.2,0.2)) ,border=FALSE) showColors(IDPcolorRamp(200, t(col2hsv(c("darkviolet","blue", "green","yellow","red"))), fr=rep(0.25,3)),border=FALSE)
Auxilary for controlling the title of a rose plot.
title.control(text = NULL, cex = 1.5, between = if (is.null(text)) 0 else 1)
title.control(text = NULL, cex = 1.5, between = if (is.null(text)) 0 else 1)
text |
Title. |
cex |
Size of characters in title in multiples of |
between |
Distance between title and label North. Default units
are |
Returns the arguments conveniently packaged up in a list to supply the
arguments for the title of plot.rose
.
Rene Locher
title.control()
title.control()
Function to zoom in and out by mouse click in a 2D-plot.
zoom(fun = plot, zoom.col = "red", delay = 3, ...)
zoom(fun = plot, zoom.col = "red", delay = 3, ...)
fun |
2D-plotting function |
zoom.col |
Color of clicked points |
delay |
Number of sec during which the 2 zooming points are shown on the plot before zooming |
... |
Arguments to plotting function |
When the clicked points lay within the plot region range, the points define the new plotting limits. When the clicked points lay in the margin, the plotting limits will be moved into the corresponding direction by 1/3 out of the actual range. There is no special sequential order for the zooming points required. The zooming function is stopped by right clicking and choosing the menu item "stop".
No value returned.
Rene Locher
i <- 1:100 y <- i*sin(i*(pi/16)) y <- c(rev(y),y) ## Not run: zoom(fun=plot, zoom.col="red", x=1:200, y=y, type="l", xlab="index") ## End( Not run)
i <- 1:100 y <- i*sin(i*(pi/16)) y <- c(rev(y),y) ## Not run: zoom(fun=plot, zoom.col="red", x=1:200, y=y, type="l", xlab="index") ## End( Not run)