rp.plot4d {rpanel} | R Documentation |
Animated scatterplot
Description
This function plots two covariates coloured by a response variable and animates this by a third covariate. In particular, it is useful for plotting spatiotemporal data.
Usage
rp.plot4d(x, z, y, model, group, subset, col.palette, col.breaks, col.labels,
hscale = 1, vscale = hscale, panel = TRUE,
x1lab, x2lab, zlab, ylab,
display = "image", Display = NULL,
background.plot = NULL, foreground.plot = NULL,
z.window = "normal", z.window.pars = c(min(z), sd(z)/5),
coords = rep(NA, 2), radius = 0.05, col.circle = "black",
lwd.circle = 1,
location.plot = TRUE, retain.location.plot = FALSE,
group.level, group.name,
eqscplot = FALSE, location.plot.type = "histogram")
rp.spacetime(space, time, y, model, group, subset, col.palette, col.breaks, col.labels,
hscale = 1, vscale = hscale, panel = TRUE,
x1lab, x2lab, zlab, ylab,
display = "image", Display = NULL,
background.plot = NULL, foreground.plot = NULL,
time.window = "normal",
time.window.pars = c(min(time), sd(time)/5),
coords = rep(NA, 2), radius = 0.05, col.circle = "black",
lwd.circle = 1,
location.plot = TRUE, retain.location.plot = FALSE,
group.level, group.name,
eqscplot = TRUE, location.plot.type = "histogram")
Arguments
x , space |
a two column matrix of covariates, in particular defining spatial locations. |
z , time |
a vector of values, such as times, over which the scatterplot will be animated. |
y |
a vector of response values which will be used to colour the plotted points. |
model |
a list with components |
group |
an optional factor allowing plots to be created for each factor level. |
subset |
a vector of logical values or indices which will be used to subset |
col.palette , col.breaks , col.labels |
the colour palette used to colour the points,
the break points on the scale which define the range associated with the each colour and
the labels associated with the break points. If |
hscale , vscale |
scaling parameters for the size of the plot when |
panel |
a logical value determining whether an interactive plot with control panel is created. |
x1lab , x2lab , zlab , ylab |
the axis labels of the variables |
display |
a character string which determines whether an "image" or "persp" plot is displayed. |
Display |
a logical vector which controls whether the points, and where present model and reference information, are displayed. |
background.plot , foreground.plot |
function to add further graphical material, such as a map, onto the background or foreground of the plot. |
z.window , time.window |
a character string which determines whether the window in
|
z.window.pars , time.window.pars |
a vector of length two which sets initial values for
the location and width of the |
coords |
a vector of length two which defines the location of the window in the
|
radius |
the radius of the window in the |
col.circle , lwd.circle |
the colour and line width of the circle used to define the
window in the |
location.plot |
a logical value which determines whether the mouse can be used to
interact with the |
retain.location.plot |
a logical value which determines the initial state of the
checkbox determining whether a plot of |
group.level |
the initial value of the |
group.name |
an optional character value giving a name to the |
eqscplot |
a logical value which determines whether the |
location.plot.type |
a character variable controlling whether a histogram or a density
estimate (using the lattice package) is produced when |
Details
The colour black should be avoided when using a normal window shape for z
. This is because hsv shading is used to indicate increasing distance from the current z
location and black has an hsv representation with s component 0, which cannot therefore be reduced further.
Value
Nothing is returned.
References
rpanel: Simple interactive controls for R functions using the tcltk package. Journal of Statistical Software, 17, issue 9.
Examples
## Not run:
# The quakes data
with(quakes, {
rp.plot4d(cbind(long, lat), depth)
rp.plot4d(cbind(long, lat), depth, mag)
})
# SO2 over Europe
with(SO2, {
location <- cbind(longitude, latitude)
if (require(mgcv) & require(maps)) {
location1 <- location[,1]
location2 <- location[,2]
model <- gam(logSO2 ~ s(location1, location2, year))
loc1 <- seq(min(location1), max(location1), length = 30)
loc2 <- seq(min(location2), max(location2), length = 30)
yr <- seq(min(year), max(year), length = 30)
newdata <- expand.grid(loc1, loc2, yr)
names(newdata) <- c("location1", "location2", "year")
model <- predict(model, newdata)
model <- list(x = cbind(loc1, loc2), z = yr,
y = array(model, dim = rep(30, 3)))
mapxy <- map('world', plot = FALSE,
xlim = range(longitude), ylim = range(latitude))
rp.plot4d(location, year, logSO2, model,
col.palette = rev(heat.colors(20)),
foreground.plot = function() map(mapxy, add = TRUE))
}
else
rp.plot4d(location, year, logSO2, col.palette = rev(heat.colors(20)))
})
# Dissolved Oxygen in the River Clyde
with(Clyde, {
rp.plot4d(cbind(Doy, DO), Station, location.plot = FALSE)
rp.plot4d(cbind(Station, DO), Doy, location.plot = FALSE)
rp.plot4d(cbind(Station, Doy), Year, DO)
# Highlight the data before and after a sewage treatment plant update in 1985
ind <- Year >= 80 & Year <= 89 & !(Year == 85)
year <- Year[ind] + Doy[ind] / 365
station <- Station[ind]
doy <- Doy[ind]
do <- DO[ind]
group <- factor(c("after 1985", "before 1985")[1 +
as.numeric(year < 85)])
rp.plot4d(cbind(doy, do), station, group,
col.palette = c("red", "green"), location.plot = FALSE)
})
## End(Not run)