
Last chance! 50% off unlimited learning
Sale ends in
Generates multiple plotly graphics, driven by specs in a data frame
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
)
plotly
object produced by subplot
input data frame
formula specifying the x-axis variable
formula for y-axis variable
formula for upper x variable limits (x
taken to be lower value)
formula for upper y variable limit (y
taken to be lower value)
formula for hovertext variable
formula specifying a variable in data
that when stratified on produces a separate plot
formula specifying an optional stratification variable
a fitting such as loess
that comes with a predict
method. Alternatively specify fitter='ecdf'
to use an internal function for computing and displaying ECDFs, which moves the analysis variable from the y-axis to the x-axis
plotly
formula 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.
plotly
formula specifying a symbol size variable or AsIs
if fitter
is given, set to TRUE
to show raw data points in addition to smooth fits
set to TRUE
to reverse the roles of x
and y
, for example to get horizontal dot charts with error bars
x-axis label. May contain html.
a named vector of y-axis labels, possibly containing html (see example below). The names of the vector must correspond to levels of the multplot
variable. ylab
can be unnamed if multplot
is not used.
position of y-axis labels. Default is on top left of plot. Specify ylabpos='y'
for usual y-axis placement.
2-vector of x-axis limits, optional
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 of the combined image in pixels
width of the combined image in pixels
the number of rows to produce using subplot
the number of columns to produce using subplot
(specify at most one of nrows,ncols
)
the color palette. Leave unspecified to use the default plotly
palette
alpha transparency for line segments (when xhi
or yhi
is not NA
)
alpha transparency for lines used to connect points
number of significant digits to use in constructing hovertext
set to FALSE
to suppress vertical line at x=0
Frank Harrell
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.
if (FALSE) {
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('X12', 'm/sec2', 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'))
}
Run the code above in your browser using DataLab