3.3.pems.plots {pems.utils} | R Documentation |
Various plot functions and visualization tools for pems
objects.
#new plots #pemsPlot pemsPlot(x, y = NULL, z = NULL, ..., data = NULL, cond = NULL, units = TRUE, fun.name="pemsPlot", panel = panel.pemsPlot, scheme = pems.scheme) #pemsPlot elements pemsXYZCondUnitsHandler(x, y = NULL, z = NULL, cond = NULL, data = NULL, units = TRUE, ..., fun.name = "pemsXYZCondHandler") preprocess.pemsPlot(lattice.like = lattice.like, units = units, ...) panel.pemsPlot(..., loa.settings = FALSE) #WatsonPlot WatsonPlot(speed, accel = NULL, z = NULL, ..., data = NULL, cond = NULL, units = TRUE, plot.type = 2, fun.name="WatsonPlot", scheme = pems.scheme) #WatsonPlot elements preprocess.WatsonPlot(lattice.like = lattice.like, ...) panel.WatsonBinPlot(..., ref.line = TRUE, process.panel = panel.binPlot, plot.panel = panel.binPlot, omit.stopped = FALSE, process = TRUE, plot = TRUE, loa.settings = FALSE) panel.WatsonContourPlot(..., plot.panel=panel.kernelDensity, process = TRUE, plot = TRUE, loa.settings = FALSE) panel.WatsonSmoothContourPlot(..., plot.panel=panel.surfaceSmooth, process = TRUE, plot = TRUE, loa.settings = FALSE) #ggplot2 (tidyverse) ## S3 method for class 'pems' fortify(model, data, ...) #old plots latticePlot(x = NULL, data = NULL, plot = xyplot, panel = NULL, ..., greyscale = FALSE, fun.name = "latticePlot") panel.PEMSXYPlot(..., grid=NULL) XYZPlot(x = NULL, ..., data = NULL, statistic = NULL, x.res = 10, y.res = 20, plot = levelplot, fun.name = "XYZPlot")
x, y, z, cond |
(Various) The main plot elements. For new plots, these should be supplied individually, e.g.
for
For old plots, these must be formulae. For For See Notes and Examples. |
data |
(Optional |
units |
(Optional |
... |
(Optional) Other arguments, typically passed on. |
fun.name |
(Function management argument) |
panel, plot.panel, process.panel |
(Functions) These functions are used to generate the content of individual plot panels.
Typically, all in-panel data processing and plotting is carried out using |
scheme |
( |
lattice.like, plot, process, loa.settings |
(Various) Plot management elements. These can typically be ignored by most users, but allow plot developers to fine-tune plots. See Details below. |
speed, accel |
(Various) For |
ref.line |
(Logical or list) For |
omit.stopped |
(Logical or character) For WatsonPlot. How to handle idling data: |
plot.type |
(numeric) For WatsonPlot. Pre-set plot types: |
greyscale |
(Logical) For older plots. Should the plot be greyscale by default? This option resets
the |
grid |
(List) If supplied, a list of plot parameters to be used to control the appearance of the grid component of the plot. See Below. |
statistic |
(Function) when binning data with |
model |
(pems.object) The pems object to be used as a data source when plotting using ggplot2 code. See below. |
x.res, y.res |
(Numerics) when binning data with |
pems.utils
includes conventional plot
methods for pems
and
pems.element
objects.
However, it also includes a range of higher level plotting functions developed using
the lattice
and loa
packages.
Early plots, e.g. latticePlot
, only allowed plot arguments using the
lattice
formula format. While this is flexible and very powerful
system, some users preferred the more conventional plot(x,y,..)
call format.
So, newer plots, e.g. pemsPlot
, allow both conventional plot and
lattice
-style formula calls.
pemsXYZCondUnitsHandler
handles the two plot call styles by converting
conventional plot calls to formula-based calls. It is typically included in a function
like pemsPlot
at an early stage. After it is run, the returned x
can be treated as a formula and y
, z
and cond
can be ignored. This
routine is included as a discrete function within this package and others are welcome to
use elsewhere for similar purposes. edit(pemsPlot)
to see it.
Newer plots also use a combination of lattice
and loa
functions to provide a range of additional plotting options, such as integrated panel and key
management. See loa
documentation for further details.
preprocess...
and panel...
functions handle pre-plot and in-plot elements
of plot generation. These use the loa
modification of the lattice
plotting framework.
See Notes and Examples.
The fortify
method was developed by Hadley Wickham to simplify the integration
of ggplot2
functions and special object classes. It is a really nice idea for
multiple reasons, the main one being that package users will probably never have to
worry about it. However, having it means you can use a pems
object directly
as the data argument with ggplot2
code.
pemsPlot
generates a bubble plot, so it plots (x,y)
points, and
by default color-grades and size-scales them according to z
.
If supplied speed and accel as x
and y
cases, the WatsonPlot
generates various forms of Watson's classic speed/accel frequency distribution
plot.
latticePlot
and XYZPlot
are general purpose 'xy' and 'xyz' data
plotting functions.
fortify
is intended for used with ggplot2 code when both pems.utils and
ggplot2 are loaded.
IMPORTANT: Conditioning is currently disabled on XYZPlot
.
XYZPlot
is a short-term replace for previous function quickPlot
. It will most likely
be replaced when pems.utils.0.3
is released.
pemsPlot
and WatsonPlot
no longer accept formula x
, y
, z
inputs.
With all these functions I have tried to make the default plotting options as robust as possible. However, it is not always possible to test all the plot combines that users might try. So, please let me know if anything is not working nicely for you. Thanks.
General, other arguments:
Like most other plot functions in R
, lattice
functions
use a number of common parameter terms. For example, xlab
and ylab
reset the x and
y labels of a graph; xlim
and ylim
set the x- and y-scales of a graph; col
sets the color of a plot element; type
sets the type ('p' for points, 'l' for lines, etc);
pch
and cex
set plot symbol type and size, respectively; and, lty
and
lwd
set plot line type and thickness, respectively; etc. These terms are passed onto and
evaluated by all these plot functions to provide standard plot control.
latticePlot
:
The default plot
option for latticePlot
is xyplot
.
panel
options for latticePlot
: Default panel.xyplot
. The
alternative panel, panel.PEMSXYPlot
supplied as part of this package, adds a
grid layer to a standard xy panel. It is simply made using two panels, panel.grid
and panel.xyplot
, both in lattice
. edit{panel.PEMSXYPlot}
to have a look at it. The extra code just allows you to pass specific plot parameters to the grid panel
using the argument grid
. You can build almost any plot layout using these and other panels
in lattice
as building blocks.
XYZPlot
:
The default plot
option for latticePlot
is levelplot
.
pemsPlot
:
pemsPlot
and subsequent plot functions use an alternative convention. Here, plot
is
a logical, which is used with another logical, process
, to tell the plot function that
data processing and plotting steps need to be handled separately. This option is particularly useful
if a calculation is carried in-plot panel that affects the plot appearance and this needs to be
integrated with other panels and keys. The handling mechanism is part of the loa
package.
The reason for latticePlot
, etc:
latticePlot
combines a number of lattice
and latticeExtra
functions modifications
I regularly use when plotting data. So, it is basically a short cut to save having to write out a lot
of code I regularly use. I would encourage anyone to at the very least have a look at lattice
.
I also hope those learning lattice
, find these functions a helpful introduction and handy 'stop
gap' while they are getting to grips with the code behind trellis and panel structures.
Karl Ropkins
lattice:
Sarkar, Deepayan (2008) Lattice: Multivariate Data Visualization with R. Springer, New York. ISBN 978-0-387-75968-5
latticeExtra:
Deepayan Sarkar and Felix Andrews (2011). latticeExtra: Extra Graphical Utilities Based on Lattice. R package version 0.6-18. http://CRAN.R-project.org/package=latticeExtra
lattice
is one of number of really nice graphical tools in R
.
Others, like ggplot2
and iplot
, help you to very
quickly explore your data. But, for me the trellis framework of lattice
has always been the most flexible.
ggplot2:
H. Wickham. ggplot2: elegant graphics for data analysis. Springer New York, 2009.
(See Chapter 9, section 9.3, pages 169-175, for discussion of fortify.)
See lattice
, latticeExtra
, loa
.
########### ##example 1 ########### ## Not run: #plotting pems with other packages #base plot(pems.1) plot(pems.1$velocity) #lattice xyplot(velocity~local.time, data = pems.1, type = "l") #in ggplot2 #Note: Suggests only so you need to load this... #Note: this uses fortify.pems require(ggplot2) qplot(time.stamp, velocity, data=pems.1) ggplot(pems.1, aes(x = time.stamp, y = velocity)) + geom_line() #etc ## End(Not run) ########### ##example 2 ########### #basic usage of latticePlot latticePlot(velocity~local.time, data = pems.1, type = "l") latticePlot(velocity~local.time, data = pems.1, col = "red", pch = 20, panel = panel.PEMSXYPlot, grid = list(col ="black", lty=2)) ########### ##example 3 ########### #basic usage of XYZPlot a <- calcAccel(velocity, local.time, data = pems.1, output="pems") XYZPlot(~accel*velocity, data=a) XYZPlot(~accel*velocity, data=a, plot = wireframe, shade=TRUE) ########### ##example 4 ########### #basic usage of pemsPlot pemsPlot(local.time, velocity, data=pems.1, type="l") ########### ##example 5 ########### #basic usage of WatsonPlot #Note: using 'a' generated in example 3 WatsonPlot(velocity, accel, data=a) ## Not run: #omit.stopped for different handling of idling data WatsonPlot(velocity, accel, data=a, omit.stopped="points") WatsonPlot(velocity, accel, data=a, omit.stopped="cells") #plot.type for different plot methods WatsonPlot(velocity, accel, data=a, plot.type=1) WatsonPlot(velocity, accel, data=a, plot.type=2) WatsonPlot(velocity, accel, data=a, plot.type=3) WatsonPlot(velocity, accel, data=a, plot.type=4) ## End(Not run)