I had 2 different sets of data which I wanted to compare using a boxplot. However the number of samples / entries I have for each of the 2 types differ.

Should I just create a boxplot for both of them even though the counts don't match or should I be performing some kind of random sampling in the data which has a higher number of samples so that both the distributions have the same number and then create boxplots for them?

What is the appropriate way to handle this situation?

  • $\begingroup$ What would it mean to "compare" them in this context? Do you just want to see what the two look like? Do you want a test of whether the means are the same? Something else? $\endgroup$ Feb 18, 2017 at 1:20
  • $\begingroup$ Are you saying you want to compare the distribution of a categorical variable to the distribution of a continuous variable? (That doesn't make any sense, but your phrasing sounds like that.) I wonder if you mean that you want to compare a continuous distribution at different levels of a categorical variable. (Can you provide a small dataset / example to clarify your situation?) This still doesn't explain what you mean by "compare" here. Do you just want to examine them descriptively, or do you want to test them, or something else (what)? $\endgroup$ Feb 18, 2017 at 1:41
  • $\begingroup$ The 2 distributions represent a yes/no variable and they each consist of some continuous data which could be negative as well. For example the distributions could be like: Yes -> 0.02, -0.01, 0, 0.005, 2 No -> 0.05, -0.04 But the 2 distributions have different number of samples, for instance in the above example Yes has 5 while No has 2. By generating a boxplot for each of the distributions, I want to compare the 2 distributions to see if there is any difference between them. Hope this makes sense. $\endgroup$
    – Kevin
    Feb 18, 2017 at 1:43

1 Answer 1


You certainly can make boxplots. There's nothing to stop you, and it isn't technically invalid in any sense. But with a dataset so small, the typical recommendation is just to show the data.

Here are boxplots and dotplots of your data, coded with R:

Yes = c(0.02, -0.01, 0, 0.005, 2) 
No  = c(0.05, -0.04)
d   = as.data.frame(stack(list(Yes=Yes, No=No)))

  layout(matrix(1:2, nrow=2))
  boxplot(values~ind, d, horizontal=T, las=1, main="Boxplot")

  plot(d$values, ifelse(d$ind=="Yes",2,1), axes=F, ylab="", ylim=c(.5,2.5), main="Dotplot")
  box(); abline(h=1:2, lty="dotted", col="gray")
  axis(side=1, at=seq(from=0, to=2, by=.5))
  axis(side=2, at=1:2, labels=c("No", "Yes"), las=1)

enter image description here

  • $\begingroup$ Thanks !! The dataset is not actually that small. I just gave an example. There are about 100 entries for which of the 2 distributions. Are there any good resources or specific books you would recommend for someone who is starting off in statistics and wants to learn about the different techniques, tests and graphs one should use? I have a brief idea about the T-test, Pearson's Coefficient, statistical significance, etc. but I want to get a deeper understanding of these topics. $\endgroup$
    – Kevin
    Feb 18, 2017 at 3:43
  • $\begingroup$ How many data do you have in each category exactly, @Kevin? We have a tag for references, which catalogues questions seeking books etc. If you click the link, you will get a list of the threads. You can sort them & search for information that is similar to your needs. There should be several such threads. $\endgroup$ Feb 18, 2017 at 4:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.