0
$\begingroup$

I have a set of discrete observations at multiple time points (~40) all of which are at similar scales i.e., between 0 and 10, and have been trying to determine the best visualization to show the individual distributions in one plot, ideally without just plotting summary statistics via box-plots or something similar (although this may very well turn out to be the best option in the end). Is there any suggestions of plots suited to such visualizations, ideally in ggplot?

Other options I've thought of is a line-chart for the mean along with 95% percentiles at each time point and appears to be the best option at the moment. Below is some simulated data (the real dataset is much larger, and more varied in distribution).

df = data.frame(points = c(), time = c())

for (i in 1:40){
  temp <- as.data.frame(cbind(sqrt(i)*sample(1:10, 10000, replace=T), rep(i,10000)))
  names(temp) <- c('points','time')
  df <- rbind(df, temp)
}

ggplot(df %>% 
  group_by(time) %>% 
  summarise(`025%`=quantile(points, probs=0.025),
            `0975%`=quantile(points, probs=0.975),
            avg=mean(points)), aes(x = time, y = avg)) +
  geom_ribbon(aes(ymax = `0975%`, ymin = `025%`), fill = 'red',
              alpha = 0.1, show.legend = FALSE) +
  geom_line(size = 1, col = 'red') + 
  geom_point()

Any comments would be greatly appreciated.

$\endgroup$
  • $\begingroup$ 40 histograms with 10 bins each might well work. $\endgroup$ – Nick Cox Oct 7 '19 at 16:38
  • $\begingroup$ Thanks for the reply Nick, agreed that a histogram is a great way to plot the distribution. However I feel as though 40 histograms in a single plot would be much to cluttered... in the end it may prove to be the best option but hoping to hear some alternative suggestions. $\endgroup$ – jmaths Oct 7 '19 at 17:29
  • $\begingroup$ I don't have your data, but it seems that you haven't even tried this suggestion. $\endgroup$ – Nick Cox Oct 7 '19 at 17:40
1
$\begingroup$

I like 2D kernel density plots, which are very similar to your plot. They differ in showing continuous variation, not just the means and confidence intervals. This is an example I found through google:

enter image description here

The X-axis would be time in your case, of course.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ This works nicely for continuous data, but with only 11 discrete values available it's likely to fail. $\endgroup$ – whuber Oct 7 '19 at 16:46
  • $\begingroup$ @whuber Why do you think it is likely to fail? I would expect it to work fine, though the plot would be more blocky than the example here. $\endgroup$ – mkt - Reinstate Monica Oct 7 '19 at 16:51
  • $\begingroup$ Nice suggestion, will definitely take a look at such plots. $\endgroup$ – jmaths Oct 7 '19 at 17:31
  • 1
    $\begingroup$ That's exactly right. Not only that, but with many data of this form the effective range is much smaller than the nominal range. For instance, responses to happiness questionnaires tend to be in the 5-10 range, with the vast bulk between 6 and 9: just four separate values. Wouldn't all details of the distribution get lost in that "blockiness"? This seems to call for a different method of visualization, one designed to represent such discrete probabilities. $\endgroup$ – whuber Oct 7 '19 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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