13
$\begingroup$

Is it "okay" to add a vertical line to a histogram to visualize the mean value?

It seems okay to me, but I've never seen this in textbooks and the likes, so I'm wondering if there's some sort of convention not to do that?

The graph is for a term paper, I just want to make sure I don't accidentally break some super important unspoken stats rule. :)

$\endgroup$
  • $\begingroup$ Why not. Just to add a comment. The mean is a summary value as the histogram is. You can vary the degree of information provided varying the bucket size of the histogram for example. However, usually the histogram provides more information than just the mean. You can actually approximate the mean value from an histogram. I think that is why they are not usually provided together. $\endgroup$ – Simone Mar 19 '13 at 22:53
  • $\begingroup$ One sometimes sees histograms with an overlaid distribution (e.g. most commonly in my experience, the normal distribution plotted using the sample mean and standard deviation.) Which is doing the same thing (and a bit more) as drawing a vertical line (indicating where sample mean is with the peak of the curve.) $\endgroup$ – James Stanley Mar 20 '13 at 23:27
30
$\begingroup$

Of course, why not?

histogram with mean

Here's an example (one of dozens I found with a simple google search):

hist with mean and median

(Image source is is the measuring usability blog, here.)

I've seen means, means plus or minus a standard deviation, various quantiles (like median, quartiles, 10th and 90th percentiles) all displayed in various ways.

Instead of drawing a line right across the plot, you might mark information along the bottom of it - like so:

histogram with marginal boxplot

There's an example (one of many to be found) with a boxplot across the top instead of at the bottom, here.

Sometimes people mark in the data:

histogram rugplot with jitter
(I have jittered the data locations slightly because the values were rounded to integers and you couldn't see the relative density well.)

There's an example of this kind, done in Stata, on this page (see the third one here)

Histograms are better with a little extra information - they can be misleading on their own

You just need to take care to explain what your plot consists of! (You'd want a better title and x-axis label than I used here, for starters. Plus an explanation in a figure caption explaining what you had marked on it.)

--

One last plot:

histogram with stripchart

--

My plots are generated in R.

Edit:

As @gung surmised, abline(v=mean... was used to draw the mean-line across the plot and rug was used to draw the data values (though I actually used rug(jitter(... because the data was rounded to integers).

Here's a way to do the boxplot in between the histogram and the axis:

hist(Davis2[,2],n=30)
boxplot(Davis2[,2],
  add=TRUE,horizontal=TRUE,at=-0.75,border="darkred",boxwex=1.5,outline=FALSE)

I'm not going to list what everything there is for, but you can check the arguments in the help (?boxplot) to find out what they're for, and play with them yourself.

However, it's not a general solution - I don't guarantee it will always work as well as it does here (note I already changed the at and boxwex options*). If you don't write an intelligent function to take care of everything, it's necessary to pay attention to what everything does to make sure it's doing what you want.

Here's how to create the data I used (I was trying to show how Theil regression was really able to handle several influential outliers). It just happened to be data I was playing with when I first answered this question.

 library("car")
 add <- data.frame(sex=c("F","F"),
       weight=c(150,130),height=c(NA,NA),repwt=c(55,50),repht=c(NA,NA))
 Davis2 <- rbind(Davis,add)

* -- an appropriate value for at is around -0.5 times the value of boxwex; that would be a good default if you write a function to do it; boxwex would need to be scaled in a way that relates to the y-scale (height) of the boxplot; I'd suggest 0.04 to 0.05 times the upper y-limit might often be okay.

Code for the marginal stripchart:

 hist(Davis2[,2],n=30)
 stripchart(jitter(Davis2[,2],amount=.5),
       method="jitter",jitter=.5,pch=16,cex=.05,add=TRUE,at=-.75,col='purple3')
$\endgroup$
  • $\begingroup$ +1, these are nice; care to add the code? abline(v=mean(Davis2[,2])) & rug(Davis2[,2]) I would guess, but how did you wedge the boxplot in there? $\endgroup$ – gung - Reinstate Monica Apr 10 '13 at 2:45
  • 1
    $\begingroup$ @gung See the edit for brief details, including a reproducible example similar to the one with the boxplot. It's really doing nothing more clever than making use of several of the arguments to the boxplot function. Between boxplot and boxp you can do some rather nifty things with little effort. $\endgroup$ – Glen_b -Reinstate Monica Apr 10 '13 at 3:29
  • $\begingroup$ Wisdom for the ages: "If you don't write an intelligent function to take care of everything, it's necessary to pay attention to what everything does to make sure it's doing what you want" ;-). $\endgroup$ – gung - Reinstate Monica Apr 10 '13 at 3:45
  • $\begingroup$ Yep. I even contemplated writing something clever to set at and boxwex and so on... but at best I only do a few plots like that a year, and it takes a few seconds each time to type ?boxplot and set the right options. I figured it's easier to just pay attention to what I am doing. $\endgroup$ – Glen_b -Reinstate Monica Apr 10 '13 at 4:14
  • $\begingroup$ @gung I edited to give code to create the Davis2 data I was using. Hope that helps. $\endgroup$ – Glen_b -Reinstate Monica Apr 10 '13 at 8:55
3
$\begingroup$

Of course you can. Just be sure to clearly label/indicate what the line means, and avoid making the plot too 'busy'.

Nothing is worse than a graph that conveys too much information to be easily understandable. The table is an often overlooked way to display summary statistics in a clear, concise matter.

$\endgroup$
2
$\begingroup$

Previous answers make excellent points, but here is one fundamental to be added.

The mean is the centre of gravity of a distribution and so the pivot point of a histogram. It is where the distribution would balance. So, there is a reciprocal relation: not only can the mean help you think about a histogram, so also can a histogram help you think about the mean. This is even perhaps more helpful when a distribution is skewed and the mean of the distribution is not necessarily in the middle.

$\endgroup$
1
$\begingroup$

I see no problem with it, see this, this, and this as examples.

$\endgroup$

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.