Why Use Hexagonal Bins?
A scatterplot is often the clearest way to see the relationship between two quantitative variables. But when a data set contains many observations, points can cover one another. A dense patch may look like a single dark mark, and it can be hard to tell whether nearby regions contain similar numbers of observations. A hexbin plot addresses this overplotting by dividing the plot into hexagonal regions and representing the number of observations in each region with color.
For example, imagine plotting study hours against quiz scores for thousands of hypothetical students. A hexbin plot can reveal where records are concentrated across the two variables. It does not display each student's point separately, however, so the choice of bin size and color scale matters: either can make a pattern easier to see or conceal useful detail.
What a Hexagon Represents
Let \(n\) be the number of observed pairs, and let \(B_j\) denote the \(j\)th hexagonal bin. Its count is
where \(I(\text{statement})\) is 1 when the statement is true and 0 otherwise. Thus, \(c_j\) is a nonnegative integer. If bins cover the full plotting region and every observation is assigned to exactly one bin, their counts sum to \(n\). Points exactly on a shared boundary need a consistent assignment rule so they are counted once, not twice.
A darker or more intense hexagon usually indicates a larger count, but the legend determines the actual meaning of its color. The count refers to the number of recorded pairs in that region. It is not the mean response, the typical response, or a fitted value. Those are different quantities. Nor is a high count automatically evidence of a high response: it indicates that many observations lie in that part of the \(x\)-\(y\) plane.
If all hexagons have equal area, their counts can be compared directly as counts per bin. A count per unit area can also be computed by dividing by hexagon area. If bin areas differ, raw counts alone are not a fair comparison of concentration: a larger bin can contain more observations simply because it covers more area. Most standard hexbin displays use a regular grid of equal-area hexagons.
Worked Example: Reading Counts in a Dense Plot
Suppose a hypothetical data set contains 5,000 student records, each with study hours on the horizontal axis and quiz score on the vertical axis. One hexagon contains 186 records, and a neighboring hexagon contains 124. What can be concluded from those counts?
The first hexagon contains \(186\) of the \(5{,}000\) records. Its share of the data is
The neighboring hexagon's share is
Because the hexagons have equal area, the first contains 62 more records than the second. These counts describe where the observed student records are concentrated in the plot. They do not say that students in the first bin studied more, scored higher, or would have done so under a different study schedule. The location of each hexagon supplies its ranges of study hours and quiz scores; the count supplies how many records fall in those ranges.
Choosing Bin Size
Bin size controls the level of detail. A grid with larger hexagons combines observations over broader ranges of both variables. This can make a broad concentration easier to see, but may merge distinct clusters or hide curvature. Smaller hexagons preserve finer local structure, but many bins may contain only a few observations. The resulting display can look speckled, and small changes in the data or grid placement can produce noticeable changes in individual counts.
There is no single bin size that is best for every data set. Choose one that is small enough to show features relevant to the question but large enough that the display does not consist mostly of isolated, unstable-looking counts. Check the ranges and units of both variables, the number of observations, and the density of the plotted region. It is also useful to compare a small number of sensible resolutions. If a pattern appears only at one arbitrary setting and disappears under a modest adjustment, treat it cautiously.
Worked Example: Comparing Two Resolutions
A hypothetical data set has 8,000 paired measurements over a fixed plotting region. A coarser grid divides the region into 40 equal-area hexagons; a finer grid uses 160 equal-area hexagons over the same region. Compare the average count per hexagon under each display.
For the coarser grid,
observations per hexagon on average. For the finer grid,
observations per hexagon on average. The finer grid has four times as many bins, so its average count per bin is one quarter as large. This arithmetic does not mean that every fine bin has 50 observations; counts will vary across the plotting region. It does show why colors cannot be compared across resolutions as though the bins represented the same amount of data.
Suppose the coarser display shows one broad high-count area, while the finer one separates it into two peaks. The finer view suggests more local structure worth investigating, but it does not by itself prove that there are two distinct underlying groups. A reasonable next step is to check whether that separation remains visible at nearby bin sizes and in the original data or another appropriate display.
Color Scales and Comparability
The color scale translates counts into visual intensity. With a linear count scale, equal changes in count correspond to equal steps in the numerical scale. This is often easy to explain, but a few very high-count bins can dominate the colors. Then low and moderate counts may look nearly identical, even when their differences are useful.
A transformed scale, such as \(\log_{10}(c_j+1)\), can spread out the lower counts while compressing the highest ones. Adding 1 allows an empty bin with count zero to be included because \(\log_{10}(1)=0\). The scale must be stated clearly in its legend. The color of a transformed value does not represent a count difference on the original scale.
Worked Example: Making Small Counts Visible
In a hypothetical hexbin plot, four bins have counts 1, 10, 100, and 1,000. Under a linear scale, the largest count is 1,000 times the smallest, so a color scale spanning 0 to 1,000 may make the bins with counts 1 and 10 look almost the same as empty bins.
Consider instead transforming each count \(c\) to \(\log_{10}(c+1)\). The four values are approximately
The transformed values now span about 0.301 to 3.000, rather than 1 to 1,000. This can make differences among lower-count bins more visible. The legend should say that color encodes \(\log_{10}(c+1)\), not raw count. A viewer can then recover the meaning: for example, a transformed value of about 2 corresponds to a count of about \(10^2-1=99\).
Making the Display Trustworthy
A useful hexbin plot should make its visual encoding clear. Label both axes with the variable names and measurement units, and include a legend that identifies whether color represents raw counts, relative frequencies, or a transformed quantity. State the bin resolution or a meaningful description of the bin dimensions when that information is needed to interpret the plot. Keep the plotted ranges and bin sizes consistent when comparing two displays; otherwise, apparent differences may come from the display settings rather than the data.
The appearance of hexagons also depends on the coordinate scales used to draw the axes. If the horizontal and vertical axes are stretched by different amounts, a hexagon in the display may not look like a regular hexagon on the page. More importantly, visual distances and angles can change with axis scaling. Always read locations using the axis labels and scales rather than judging a relationship from the apparent shape of the colored regions alone.
Grid placement can affect counts too. Moving a regular grid slightly may shift observations from one hexagon to a neighbor, especially near boundaries. This is a consequence of summarizing continuous locations into discrete bins, not evidence that observations changed. If a conclusion depends on one sharp boundary or a single bin, check whether it remains plausible with a modest shift in the grid or a nearby bin size.
Counts also describe the records that were plotted. They should not automatically be described as the density of a broader population: that interpretation depends on how the data were collected and whether the observations represent that population. A concentrated region in a plot can reflect the sampling design, repeated measurements, or other features of the data collection as well as a real concentration in the population.
A Short Justification for Checking Resolution
Why does changing bin size alter the counts even when the observations stay fixed? For equal-area bins covering the same region, the counts still add to the same total \(n\), but the number of terms in that sum changes. If the region contains \(K\) bins, the average count is \(n/K\). Increasing \(K\) therefore decreases the average count per bin, even though no observation has been added or removed.
This explains why color patterns from different resolutions should not be compared as if each color referred to the same count range. It also explains why a finer grid can expose local variation while making individual-bin counts less stable. A hexbin plot is a visual summary at a chosen scale, not a scale-free description of the data.
Common Mistakes
- Reading color as an average response. Wrong reasoning: “This dark hexagon means the typical quiz score here is high.” Correction: in a count hexbin plot, darkness represents the number of observations, unless the legend explicitly defines a different quantity.
- Comparing counts from different bin sizes directly. Wrong reasoning: “This plot has lighter bins, so it must contain fewer observations.” Correction: finer bins usually have lower counts per bin because they cover less area. Check the total sample size, bin dimensions, and scale before comparing.
- Assuming a visible cluster is definitive. Wrong reasoning: “Two colored peaks prove there are two separate groups.” Correction: a display can reveal a pattern worth checking, but bin size and grid placement can affect its appearance. Examine whether it persists under reasonable settings.
- Calling a count population density without qualification. Wrong reasoning: “The darkest region is where people in the population are most concentrated.” Correction: the plot shows concentration among the records displayed. A population claim depends on how those records were obtained.
Check Your Understanding
Try these questions using the definitions and examples above.
- What does the color of a hexagon represent in a standard count hexbin plot, and what does it not represent?
- A display uses 100 equal-area bins for 6,000 observations. What is the average count per bin? Would every bin necessarily have that count?
- Why might a transformed color scale be helpful when a few bins have much larger counts than most others? What should the legend say?
- Give one reason to check a hexbin plot at a nearby resolution or grid placement before describing a small cluster.
- Why should observed bin counts not automatically be called population density?