I'm trying to plot a box-and-whisker plot for differences between samples obtained from two different (and presumably independent) groups (the sample numbers may differ between the groups). Because the difference between the means is not enough for the box-and-whisker plot, and thus I was wondering whether I could generate a list of the difference value between all the possible pairs and use it for the box-and-whisker plot.
It might be better to make two boxplots side by side and compare them. In some cases, one can use 'notched' boxplots.
The notches indicate nonparametric confidence intervals calibrated to facilitate deciding whether the populations for two samples differ. Nonoverlapping notches (as in the example below) suggest a significant difference.
Here is an illustration for two simulated nonnormal samples:
set.seed(2020) x1 = rgamma(100, 5, .2) x2 = rgamma(130, 5, .25) x = c(x1, x2) g = as.factor(c(rep(1,100), rep(2,130))) boxplot(x ~ g, col="skyblue2", pch=19, notch=T) summary(x1) Min. 1st Qu. Median Mean 3rd Qu. Max. 7.958 16.748 23.910 25.882 30.697 81.840 summary(x2) Min. 1st Qu. Median Mean 3rd Qu. Max. 3.96 13.23 18.45 19.14 23.03 45.96
Notes: (1) If notches extend beyond the box part of their plots, they can be a little difficult to interpret. When this happens, R provides a warning message that suggests omitting the notches. (I would not show a boxplot with 'messy' notches in a report meant for a nonstatistical audience.)
(2) A Welch 2-sample t test on the ranks of the combined samples, shows a highly significant difference. (Of course the ranks are not normal, but they have no outliers.)
t.test(rank(x) ~ g) Welch Two Sample t-test data: rank(x) by g t = 4.396, df = 207.53, p-value = 1.76e-05 alternative hypothesis: true difference in means is not equal to 0 ...