plotly Multiple
plotlyM.RdGenerates multiple plotly graphics, driven by specs in a data frame
Usage
plotlyM(
data,
x = ~x,
y = ~y,
xhi = ~xhi,
yhi = ~yhi,
htext = NULL,
multplot = NULL,
strata = NULL,
fitter = NULL,
color = NULL,
size = NULL,
showpts = !length(fitter),
rotate = FALSE,
xlab = NULL,
ylab = NULL,
ylabpos = c("top", "y"),
xlim = NULL,
ylim = NULL,
shareX = TRUE,
shareY = FALSE,
height = NULL,
width = NULL,
nrows = NULL,
ncols = NULL,
colors = NULL,
alphaSegments = 1,
alphaCline = 0.3,
digits = 4,
zeroline = TRUE
)Arguments
- data
input data frame
- x
formula specifying the x-axis variable
- y
formula for y-axis variable
- xhi
formula for upper x variable limits (
xtaken to be lower value)- yhi
formula for upper y variable limit (
ytaken to be lower value)- htext
formula for hovertext variable
- multplot
formula specifying a variable in
datathat when stratified on produces a separate plot- strata
formula specifying an optional stratification variable
- fitter
a fitting such as
loessthat comes with apredictmethod. Alternatively specifyfitter='ecdf'to use an internal function for computing and displaying ECDFs, which moves the analysis variable from the y-axis to the x-axis- color
plotlyformula specifying a color variable or e.g.~ I('black'). To keep colors constant over multiple plots you will need to specify an AsIs color when you don't have a variable representing color groups.- size
plotlyformula specifying a symbol size variable or AsIs- showpts
if
fitteris given, set toTRUEto show raw data points in addition to smooth fits- rotate
set to
TRUEto reverse the roles ofxandy, for example to get horizontal dot charts with error bars- xlab
x-axis label. May contain html.
- ylab
a named vector of y-axis labels, possibly containing html (see example below). The names of the vector must correspond to levels of the
multplotvariable.ylabcan be unnamed ifmultplotis not used.- ylabpos
position of y-axis labels. Default is on top left of plot. Specify
ylabpos='y'for usual y-axis placement.- xlim
2-vector of x-axis limits, optional
- ylim
2-vector of y-axis limits, optional
specifies whether x-axes should be shared when they align vertically over multiple plots
specifies whether y-axes should be shared when they align horizontally over multiple plots
- height
height of the combined image in pixels
- width
width of the combined image in pixels
- nrows
the number of rows to produce using
subplot- ncols
the number of columns to produce using
subplot(specify at most one ofnrows,ncols)- colors
the color palette. Leave unspecified to use the default
plotlypalette- alphaSegments
alpha transparency for line segments (when
xhioryhiis notNA)- alphaCline
alpha transparency for lines used to connect points
- digits
number of significant digits to use in constructing hovertext
- zeroline
set to
FALSEto suppress vertical line at x=0
Details
Generates multiple plotly traces and combines them with plotly::subplot. The traces are controlled by specifications in data frame data plus various arguments. data must contain these variables: x, y, and tracename (if color is not an "AsIs" color such as ~ I('black')), and can contain these optional variables: xhi, yhi (rows containing NA for both xhi and yhi represent points, and those with non-NA xhi or yhi represent segments, connect (set to TRUE for rows for points, to connect the symbols), legendgroup (see plotly documentation), and htext (hovertext). If the color argument is given and it is not an "AsIs" color, the variable named in the color formula must also be in data. Likewise for size. If the multplot is given, the variable given in the formula must be in data. If strata is present, another level of separate plots is generated by levels of strata, within levels of multplot.
If fitter is specified, x,y coordinates for an individual plot are
run through fitter, and a line plot is made instead of showing data points. Alternatively you can specify fitter='ecdf' to compute and plot emirical cumulative distribution functions.
Examples
if (FALSE) { # \dontrun{
set.seed(1)
pts <- expand.grid(v=c('y1', 'y2', 'y3'), x=1:4, g=c('a', 'b'), yhi=NA,
tracename='mean', legendgroup='mean',
connect=TRUE, size=4)
pts$y <- round(runif(nrow(pts)), 2)
segs <- expand.grid(v=c('y1', 'y2', 'y3'), x=1:4, g=c('a', 'b'),
tracename='limits', legendgroup='limits',
connect=NA, size=6)
segs$y <- runif(nrow(pts))
segs$yhi <- segs$y + runif(nrow(pts), .05, .15)
z <- rbind(pts, segs)
xlab <- labelPlotmath('X<sub>12</sub>', 'm/sec<sup>2</sup>', html=TRUE)
ylab <- c(y1=labelPlotmath('Y1', 'cm', html=TRUE),
y2='Y2',
y3=labelPlotmath('Y3', 'mm', html=TRUE))
W=plotlyM(z, multplot=~v, color=~g, xlab=xlab, ylab=ylab, ncols=2,
colors=c('black', 'blue'))
W2=plotlyM(z, multplot=~v, color=~I('black'), xlab=xlab, ylab=ylab,
colors=c('black', 'blue'))
} # }