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).
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 = brewer.pal(8, "Set1"),
alpha = 0.33,
jitterWidth = 0.5, jitterHeight = 0.4,
xlab = "Scores and means",
ylab = NULL,
theme = theme_bw(),
showLegend = TRUE,
lineSize = 1,
xbreaks = "auto",
outputFile = NULL,
outputWidth = 10,
outputHeight = 10,
ggsaveParams = list(units='cm',
dpi=300,
type="cairo"),
...)
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 = brewer.pal(8, "Set1"),
associationsColor = "grey",
alpha = 0.33,
jitterWidth = 0.5, jitterHeight = 0.4,
xlab = c("Scores and means", "Effect size estimates"),
ylab = c(NULL, NULL),
theme = theme_bw(),
showLegend = TRUE,
lineSize = 1,
drawPlot = TRUE,
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 items
).
The labels to use to replace the value labels of the compareBy
variable.
Whether to sort the variables by their mean values (NULL
to not sort, TRUE
to sort in descending order (i.e. items with lower means are plotted more to the bottom), and FALSE
to sort in ascending order (i.e. items with lower means are plotted more to the top).
If the variables should be sorted (see decreasing
), this variable specified which subgroup should be sorted by. Therefore, the value specified here must be a value label ('level label') of the comparisonBy
variable.
The confidence level of the confidence intervals specified by the diamonds for the means (for meansComparisonDiamondPlot
) and for both the means and effect sizes (for duoComparisonDiamondPlot
).
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.
For duoComparisonDiamondPlot
, the color to use to plot the effect sizes in the right-hand plot.
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 duoComparisonDiamondPlot
, must be vectors of two elements). Use NULL
to not use a label.
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 ggsaveParams
).
Parameters to pass to ggsave when saving the plot.
Any additional arguments are passed to diamondPlot
by meansComparisonDiamondPlot
and to both meansComparisonDiamondPlot
and associationsDiamondPlot
by duoComparisonDiamondPlot
.
Diamond plots: a ggplot
by meansComparisonDiamondPlot
, and a gtable
by duoComparisonDiamondPlot
.
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
# NOT RUN {
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));
# }
Run the code above in your browser using DataLab