These are two diamond plot functions to conveniently make diamond plots to compare subgroups or different samples. They are both based on a univariate diamond plot where colors are used to distinguish the data points and diamonds of each subgroup or sample. The means comparison diamond plot produces only this plot, while the duo comparison diamond plot combines it with a diamond plot visualising the effect sizes of the associations. The latter currently only works for two subgroups or samples, while the simple meansComparisonDiamondPlot also works when comparing more than two sets of datapoints. These functions are explained more in detail in Peters (2017).
duoComparisonDiamondPlot(dat, items = NULL, compareBy = NULL, labels = NULL, compareByLabels = NULL, decreasing = NULL, conf.level = c(0.95, 0.95), showData = TRUE, dataAlpha = 0.1, dataSize = 3, comparisonColors = viridis::viridis(length(unique(dat[, compareBy]))), associationsColor = "grey", alpha = 0.33, jitterWidth = 0.5, jitterHeight = 0.4, xlab = c("Scores and means", "Effect size estimates"), ylab = c(NULL, NULL), theme = ggplot2::theme_bw(), showLegend = TRUE, lineSize = 1, drawPlot = TRUE, xbreaks = "auto", outputFile = NULL, outputWidth = 10, outputHeight = 10, ggsaveParams = list(units = "cm", dpi = 300, type = "cairo"), ...) meansComparisonDiamondPlot(dat, items = NULL, compareBy = NULL, labels = NULL, compareByLabels = NULL, decreasing = NULL, sortBy = NULL, conf.level = 0.95, showData = TRUE, dataAlpha = 0.1, dataSize = 3, comparisonColors = viridis::viridis(length(unique(dat[, compareBy]))), alpha = 0.33, jitterWidth = 0.5, jitterHeight = 0.4, xlab = "Scores and means", ylab = NULL, theme = ggplot2::theme_bw(), showLegend = TRUE, lineSize = 1, xbreaks = "auto", outputFile = NULL, outputWidth = 10, outputHeight = 10, ggsaveParams = list(units = "cm", dpi = 300, type = "cairo"), ...)
The dataframe containing the relevant variables.
The variables to plot (on the y axis).
The variable by which to compare (i.e. the variable indicating to which subgroup or sample a row in the dataframe belongs).
The labels to use on the y axis; these values will replace the
variable names in the dataframe (specified in
The labels to use to replace the value labels of the
Whether to sort the variables by their mean values
The confidence level of the confidence intervals specified
by the diamonds for the means (for
Whether to plot the data points.
The transparency (alpha channel) value for the data points: a value between 0 and 1, where 0 denotes complete transparency and 1 denotes complete opacity.
The size of the data points.
The colors to use for the different subgroups or samples. This should be a vector of valid colors with at least as many elements as sets of data points that should be plotted.
The alpha channel (transparency) value for the diamonds: a value between 0 and 1, where 0 denotes complete transparency and 1 denotes complete opacity.
How much noise to add to the data points (to prevent overplotting) in the horizontal (x axis) and vertical (y axis) directions.
The label to use for the x and y axes (for
The theme to use for the plots.
Whether to show the legend (which color represents which subgroup/sample).
The thickness of the lines (the diamonds' strokes).
Whether to draw the plot, or only (invisibly) return it.
Where the breaks (major grid lines, ticks, and labels) on the x axis should be.
A file to which to save the plot.
Width and height of saved plot (specified in
centimeters by default, see
Parameters to pass to ggsave when saving the plot.
If the variables should be sorted (see
A Diamond plots: a
meansComparisonDiamondPlot, and a
These functions are explained in Peters (2017).
Peters, G.-J. Y. (2017). Diamond Plots: a tutorial to introduce a visualisation tool that facilitates interpretation and comparison of multiple sample estimates while respecting their inaccuracy. PsyArXiv. http://doi.org/10.17605/OSF.IO/9W8YV
meansComparisonDiamondPlot(mtcars, items=c('disp', 'hp'), compareBy='vs', xbreaks=c(100,200, 300, 400));meansComparisonDiamondPlot(chickwts, items='weight', compareBy='feed', xbreaks=c(100,200,300,400), showData=FALSE);duoComparisonDiamondPlot(mtcars, items=c('disp', 'hp'), compareBy='vs', xbreaks=c(100,200, 300, 400));#> Error in !var.equal: invalid argument type