View source: R/Plotting_Functions.R
MoE_gpairs | R Documentation |
Produces a matrix of plots showing pairwise relationships between continuous response variables and continuous/categorical/logical/ordinal associated covariates, as well as the clustering achieved, according to fitted MoEClust mixture models.
MoE_gpairs(res,
response.type = c("points", "uncertainty", "density"),
subset = list(...),
scatter.type = c("lm", "points"),
conditional = c("stripplot", "boxplot"),
addEllipses = c("outer", "yes", "no", "inner", "both"),
expert.covar = TRUE,
border.col = c("purple", "black", "brown", "brown", "navy"),
bg.col = c("cornsilk", "white", "palegoldenrod", "palegoldenrod", "cornsilk"),
outer.margins = list(bottom = grid::unit(2, "lines"),
left = grid::unit(2, "lines"),
top = grid::unit(2, "lines"),
right = grid::unit(2, "lines")),
outer.labels = NULL,
outer.rot = c(0, 90),
gap = 0.05,
buffer = 0.025,
uncert.cov = FALSE,
scatter.pars = list(...),
density.pars = list(...),
diag.pars = list(...),
stripplot.pars = list(...),
boxplot.pars = list(...),
barcode.pars = list(...),
mosaic.pars = list(...),
axis.pars = list(...),
...)
res |
An object of class |
response.type |
The type of plot desired for the scatterplots comparing continuous response variables. Defaults to Points can also be sized according to their associated clustering uncertainty with the option Alternatively, the bivariate parametric |
subset |
A list giving named arguments for producing only a subset of panels:
The results of the subsetting must ensure that at least one panel of some sort can be plotted. The arguments |
scatter.type |
A vector of length 2 (or 1) giving the plot type for the upper and lower triangular portions of the plot, respectively, pertaining to the associated covariates. Defaults to |
conditional |
A vector of length 2 (or 1) giving the plot type for the upper and lower triangular portions of the plot, respectively, for plots involving a mix of categorical and continuous variables. Defaults to All |
addEllipses |
Controls whether to add MVN ellipses with axes corresponding to the within-cluster covariances for the response data. The options Ellipses are centered on the posterior mean of the fitted values when there are expert network covariates, otherwise on the posterior mean of the response variables. In the presence of expert network covariates, the component-specific covariance matrices are also (by default, via the argument |
expert.covar |
Logical (defaults to |
border.col |
A vector of length 5 (or 1) containing border colours for plots against the MAP classification, response vs. response, covariate vs. response, response vs. covariate, and covariate vs. covariate panels, respectively. Defaults to |
bg.col |
A vector of length 5 (or 1) containing background colours for plots against the MAP classification, response vs. response, covariate vs. response, response vs. covariate, and covariate vs. covariate panels, respectively. Defaults to |
outer.margins |
A list of length 4 with units as components named |
outer.labels |
The default is typically Note that axis labels always correspond to the range of the depicted variable, and thus should not be interpreted as indicating counts or densities for the diagonal panels when |
outer.rot |
A 2-vector ( |
gap |
The gap between the tiles; defaulting to |
buffer |
The fraction by which to expand the range of quantitative variables to provide plots that will not truncate plotting symbols. Defaults to |
uncert.cov |
A logical indicating whether the expansion factor for points on plots involving covariates should also be modified when |
scatter.pars |
A list supplying select parameters for the continuous vs. continuous scatterplots.
list(scat.pch=res$classification, uncert.pch=19, scat.col=res$classification, scat.size=unit(0.25, "char"), eci.col=1:res$G, noise.size=unit(0.2, "char")), where Note also that |
density.pars |
A list supplying select parameters for visualising the bivariate parametric density contours, only when
list(grid.size=c(100, 100), dcol="grey50", dens.points=FALSE, nlevels=11, show.labels=!dens.points, label.style="mixed"), where |
diag.pars |
A list supplying select parameters for panels along the diagonal.
list(diag.fontsize=9, diagonal=TRUE, hist.color=hist.color, show.hist=TRUE, show.counts=TRUE, show.dens=FALSE, dens.grid=100), where The argument When |
stripplot.pars |
A list supplying select parameters for continuous vs. categorical panels when one or both of the entries of
list(strip.pch=res$classification, strip.size=unit(0.5, "char"), strip.col=res$classification, jitter=TRUE, size.noise=unit(0.4, "char")), where |
boxplot.pars |
A list supplying select parameters for continuous vs. categorical panels when one or both of the entries of
list(box.pch="|", box.col="black", varwidth=FALSE, notch=FALSE, notch.frac=0.5, box.fill=1:res$G). All of the above are relevant for |
barcode.pars |
A list supplying select parameters for continuous vs. categorical panels when one or both of the entries of
list(bar.col=res$G:1, nint=0, ptsize=scatter.pars$scat.size, ptpch=scatter.pars$scat.pch, bcspace=NULL, use.points=FALSE), where |
mosaic.pars |
A list supplying select parameters for categorical vs. categorical panels (if any).
list(shade=NULL, gp_labels=grid::gpar(fontsize=9), gp_args=list(), gp=list(), mfill=TRUE, mcol=1:res$G). The current default arguments and values thereof are passed through to |
axis.pars |
A list supplying select parameters for controlling the axes.
list(n.ticks=5, axis.fontsize=9). The argument |
... |
Catches unused arguments. Alternatively, named arguments can be passed directly here to any/all of |
A generalised pairs plot showing all pairwise relationships between clustered response variables and associated gating &/or expert network continuous &/or categorical variables, coloured according to the MAP classification, with the marginal distributions of each variable along the diagonal.
plot.MoEClust
is a wrapper to MoE_gpairs
which accepts the default arguments, and also produces other types of plots. Caution is advised producing generalised pairs plots when the dimension of the data is large.
Note that all colour-related defaults in scatter.pars
, stripplot.pars
, barcode.pars
, and mosaic.pars
above assume a specific colour-palette (see mclust.options("classPlotColors")
). Thus, for instance, specifying scatter.pars$scat.col=res$classification
will produce different results compared to leaving this argument unspecified. This is especially true for models with a noise component, for which the default is handled quite differently (for one thing, res$G
is the number of non-noise components). Similarly, all pch
-related defaults in scatter.pars
and stripplot.pars
above assume a specific set of plotting symbols also (see mclust.options("classPlotSymbols")
). Generally, all colour and symbol related arguments are strongly recommended to be left at their default values, unless being supplied as a single character string, e.g. "black"
for colours. To help in this regard, colour-related arguments sensibly inherent their defaults from scatter.pars$scat.col
if that is supplied and the argument in question is not.
For MoEClust
models with more than one expert network covariate, fitted lines produced in continuous covariate vs. continuous response scatterplots via scatter.type="lm"
or scatter.type="ci"
will NOT correspond to the coefficients in the expert network (res$expert
).
Caution is advised when producing "barcode"
plots for the conditional
panels. In some cases, resizing the graphics device after the production of the plot will result in distortion because of the way the rotation of non-horizontal barcodes is performed. Thus, when any(conditional == "barcode")
, it is advisable to ensure the dimensions of the overall plot are square. Furthermore, such plots may not display correctly anyway in RStudio's “Plots” pane and so a different graphics device may need to be used (but not subsequently resized).
Caution is also advised when producing generalised pairs plots when the dimension of the data is large.
Keefe Murphy - <keefe.murphy@mu.ie>
Murphy, K. and Murphy, T. B. (2020). Gaussian parsimonious clustering models with covariates and a noise component. Advances in Data Analysis and Classification, 14(2): 293-325. <\Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/s11634-019-00373-8")}>.
Emerson, J. W., Green, W. A., Schloerke, B., Crowley, J., Cook, D., Hofmann, H. and Wickham, H. (2013). The generalized pairs plot. Journal of Computational and Graphical Statistics, 22(1): 79-91.
MoE_clust
, MoE_stepwise
, plot.MoEClust
, MoE_Uncertainty
, expert_covar
, panel.stripplot
, panel.bwplot
, panel.violin
, strucplot
, mclust.options
data(ais)
res <- MoE_clust(ais[,3:7], G=2, gating= ~ BMI, expert= ~ sex,
network.data=ais, modelNames="EVE")
MoE_gpairs(res)
# Produce the same plot, but with a violin plot in the lower triangle.
# Colour the outline of the mosaic tiles rather than the interior using mfill.
# Size points in the response vs. response panels by their clustering uncertainty.
MoE_gpairs(res, conditional=c("stripplot", "violin"),
mfill=FALSE, response.type="uncertainty")
# Instead show the bivariate density contours of the response variables (without labels).
# (Plotting may be slow when response.type="density" for models with expert covariates.)
# Use different colours for histograms of covariates in the gating/expert/both networks.
# Also use different colours for response vs. covariate & covariate vs. response panels.
MoE_gpairs(res, response.type="density", show.labels=FALSE, dens.points=TRUE,
hist.color=c("black", "cyan", "hotpink", "chartreuse"),
bg.col=c("whitesmoke", "white", "mintcream", "mintcream", "floralwhite"))
# Examine effect of expert.covar & diag.grid in conjunction with show.dens & show.hist
MoE_gpairs(res, show.dens=TRUE, expert.covar=FALSE, show.hist=FALSE, diag.grid=20)
MoE_gpairs(res, show.dens=TRUE, expert.covar=TRUE, show.hist=TRUE, diag.grid=200)
# Explore various options to subset and rearrange the panels
MoE_gpairs(res, data.ind=5:1, cov.ind=0,
show.map=FALSE, show.hist=FALSE,
submat="upper", diagonal=FALSE)
# Produce a generalised pairs plot for a model with a noise component.
# Reorder the covariates and omit the variables "Hc" and "Hg".
# Use barcode plots for the categorical/continuous pairs.
# Magnify the size of scatter points assigned to the noise component.
resN <- MoE_clust(ais[,3:7], G=2, gating= ~ SSF + Ht, expert= ~ sex,
network.data=ais, modelNames="EEE", tau0=0.1, noise.gate=FALSE)
# Note that non-horizontal barcode panels may not display correctly in RStudio's "Plots" pane
# it may be necessary to first open a new device:
# dev.new()
MoE_gpairs(resN, data.ind=c(1,2,5), cov.ind=c(3,1,2), use.points=TRUE,
conditional="barcode", noise.size=grid::unit(0.5, "char"))
# Plots can be modified to show only a single (diagonal) panel of interest
MoE_gpairs(resN, data.ind=0, cov.ind=0)
MoE_gpairs(resN, data.ind=0, cov.ind="sex", show.map=FALSE)
MoE_gpairs(resN, data.ind="RCC", cov.ind=0, show.map=FALSE, show.dens=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.