Tutorials › Exam PA - Predictive Analytics › Scatterplots With Grouped Symbols

Exam PA · Visualization and Anomaly Detection · Tutorial 153 of 966

Scatterplots With Grouped Symbols

Use color and plotting symbols to compare groups in a scatterplot, while checking that the display does not hide observations or confuse the legend.

Beginner 10 min read

What You'll Learn

  • Identify the quantitative variables and categorical group used in a grouped scatterplot
  • Map group levels consistently to colors, plotting symbols, or both
  • Use R base graphics to draw and label grouped scatterplots
  • Compare the direction, range, and separation of patterns within groups
  • Check whether overlapping points obscure observations or group membership
  • Avoid misleading legends and interpretations of plotted symbols

Why Add Grouping to a Scatterplot?

A scatterplot shows the relationship between two quantitative variables, with one variable on each axis. Often, each observation also belongs to a category: for example, a policy might be sold through one of several hypothetical distribution channels, or a measurement might come from one of several laboratory procedures. Encoding that category with color or plotting symbol lets you inspect whether the point pattern differs across groups.

The purpose is not merely to make a plot more colorful. A useful grouped scatterplot makes the group membership of points readable, gives the reader a clear legend, and makes it possible to compare patterns without confusing the category with either axis variable. It also requires a check for overlap: two observations may occupy the same coordinates, so one plotted symbol can conceal another.

Definition: A grouped scatterplot displays two quantitative variables, \(x\) and \(y\), and uses a visual attribute such as color or plotting symbol to encode a categorical grouping variable \(g\). Each observation contributes a point at its \((x,y)\) coordinates; the point's appearance identifies its group, provided that appearance is visible.

Map Groups to Visual Attributes Consistently

Before plotting, identify the roles of the variables. The horizontal and vertical axes should represent quantitative measurements. The grouping variable should identify categories, not numerical amounts. A code such as 1, 2, or 3 may label categories, but it does not make those categories quantitative or imply that one group is “greater” than another.

In R base graphics, a common approach is to draw an empty plotting region, then add points for each group with points(). The col argument controls color, and pch controls plotting symbol. The legend should use the same group order and the same visual mapping as the plotted points. For example, assigning one color to each level in a fixed order is safer than relying on an implicit order that may change when the data are filtered.

A typical base R sequence is: plot(x, y, type="n", xlab="...", ylab="..."); then points(x[group=="A"], y[group=="A"], col="blue", pch=16) for each group; and finally legend("topleft", legend=c("A","B"), col=c("blue","orange"), pch=c(16,17)). The placeholder axis labels should be replaced by the names and units of the measurements. If several groups are shown, use symbols, colors, or both so the groups remain distinguishable.

Color alone can be hard to distinguish in a small figure, in grayscale, or for some viewers. Symbols alone can also become difficult to tell apart when there are many groups or many points. Using both is often useful for a modest number of groups, but adding more visual distinctions does not guarantee readability: the legend and points must still be easy to match.

Worked Example: Comparing Two Hypothetical Service Channels

A hypothetical insurer records the number of years since policy issue and a service-time measure, in hours, for six sampled service cases. The observations are: Web channel, (1, 8), (2, 10), (3, 12); telephone channel, (1, 15), (2, 14), (3, 13). Use a grouped scatterplot and compare the visible group patterns.

Method. Put years since issue on the horizontal axis and service time in hours on the vertical axis. Map Web to blue circles and telephone to orange triangles, then add a legend. The plotted coordinates are exactly the six pairs given; the colors and symbols encode only the channel.

Compare the patterns. For Web cases, service time changes from 8 hours at year 1 to 12 hours at year 3, a change of \(12-8=4\) hours. For telephone cases, it changes from 15 to 13 hours over the same two-year span, a change of \(13-15=-2\) hours. The Web points therefore rise across the displayed x-values, while the telephone points fall. The telephone values are also higher at each shared x-value: at years 1, 2, and 3 the differences are \(15-8=7\), \(14-10=4\), and \(13-12=1\) hour, respectively.

R implementation. If the vectors are named years, hours, and channel, draw the axes with plot(years, hours, type="n", xlab="Years since issue", ylab="Service time (hours)"). Add Web points using points(years[channel=="Web"], hours[channel=="Web"], col="blue", pch=16) and telephone points using points(years[channel=="Telephone"], hours[channel=="Telephone"], col="orange", pch=17). Add a legend with labels Web and Telephone and the matching colors and symbols.

Check and common mistake. Both groups have three observations, and the plotted x-values are 1, 2, and 3 for each. The comparison is within each channel at those x-values. A common mistake is to describe all six points as one rising pattern because the Web points rise; the telephone points visibly fall, so the group distinction changes the description.

What the Grouped Plot Represents

Let the data contain \(n\) observations, with coordinates \((x_i,y_i)\) and group label \(g_i\) for observation \(i\). For any group \(a\), its plotted subset is the set of points whose labels equal \(a\): \(\{(x_i,y_i): g_i=a\}\). The full scatterplot is the collection of these group-specific subsets across all group labels. This explains why consistent encoding works: when each observation has one group label and each group has a distinct visible appearance, the reader can identify which plotted points belong to each subset and compare them.

The qualification “visible” matters. If two observations have identical coordinates, their symbols occupy the same location. The mathematical data still contain both observations, but the image may show only the symbol drawn last. A legend explains what a symbol means; it cannot reveal a point hidden directly underneath another point.

Worked Example: Detecting Concealed Observations

A hypothetical portfolio team plots claim review duration against the number of documents in a file. The Standard group has points (2, 5), (4, 7), and (6, 9). The Priority group has points (2, 5), (4, 7), and (8, 9). The first coordinate is document count and the second is review duration in hours. How many records are present, how many distinct coordinate locations are present, and what can a grouped plot conceal?

Method. Count observations from the two group lists, then compare their coordinates to find exact coincidences. Standard has 3 records and Priority has 3, so there are \(3+3=6\) records. The coordinates (2, 5) and (4, 7) each occur in both groups. The other two locations, (6, 9) and (8, 9), occur once each. Thus there are 4 distinct coordinate locations.

Interpret the display. If Standard is drawn first and Priority second, the Priority symbol may cover the Standard symbol at (2, 5) and (4, 7). A viewer counting visible locations would see 4, but that is not the record count: the correct count is 6. The plot still shows the different locations at duration 9 hours, but it can conceal which groups share the first two locations.

R implementation and check. Plot each group with a different symbol and color, and inspect the shared locations explicitly. The group-specific vectors should each contain 3 points; their combined length is 6, even though the set of unique coordinate pairs has length 4. For example, calculate the number of records from the lengths of the two groups, not by counting marks on the rendered image. Transparency or jitter can sometimes help reveal overlaps, as discussed in the earlier material on overplotting; either choice should be disclosed because it changes the visual appearance or displayed coordinates.

Common mistake. The wrong calculation is “4 visible locations, therefore 4 records.” The correction is to count the underlying observations: two shared locations represent two observations apiece, and the two remaining locations represent one each, giving \(2+2+1+1=6\) records.

Read Within-Group Patterns, Not Just the Overall Cloud

After checking that the groups can be distinguished, compare them in a consistent order. Consider the direction of the points as \(x\) increases, their horizontal and vertical ranges, and whether groups occupy similar or separated regions of the plot. Describe what is visible in the displayed data; do not infer causation from a scatterplot, and do not treat a small number of points as conclusive evidence of a stable relationship.

Group-specific comparisons are easiest when the same axes and scales are used for every group. If one group is plotted on a different scale, apparent differences in spread or separation may be artifacts of the display. Also keep units in axis labels. “Duration” without its unit, for example, leaves the reader uncertain whether values refer to minutes, hours, or days.

A categorical variable’s factor levels can help keep the mapping fixed in R. Specify the intended order, then use that same order for the plotting colors, symbols, and legend. Factor order is a display and data-handling choice; for nominal categories, it does not establish a ranking among the groups.

Worked Example: Keeping a Three-Group Legend Aligned

A hypothetical analyst compares measurement \(x\), in units, with response \(y\), in points, for three inspection routes. Route North has (10, 2), (20, 4), (30, 6); Route South has (10, 7), (20, 8), (30, 9); Route West has (15, 3), (25, 3), (35, 4). Build a clear grouped display and summarize the group-specific ranges.

Method. Set the factor levels explicitly as North, South, West. Assign North blue circles, South orange triangles, and West dark-green squares, and use those exact three assignments in the legend. The horizontal range for North is \(30-10=20\), for South it is \(30-10=20\), and for West it is \(35-15=20\). The vertical ranges are North \(6-2=4\), South \(9-7=2\), and West \(4-3=1\).

Compare the positions. At each shared x-value of 10, 20, and 30, North’s y-value is below South’s: the pairs are 2 versus 7, 4 versus 8, and 6 versus 9. West covers x-values 15, 25, and 35 and has y-values 3, 3, and 4. In this sample, North’s y-values rise by \(6-2=4\) from first to last point, South’s rise by \(9-7=2\), and West’s rise by \(4-3=1\). These are descriptions of the given points, not claims about what would occur in every inspection.

R implementation. Set the group variable to a factor with levels North, South, and West in that order. Draw an empty plotting region with labeled axes, then add points using a filter for each level. Add the legend in the same order, with labels North, South, and West and matching symbols and colors. This explicit mapping prevents the legend from assigning, for example, the North symbol to South points after a change in factor ordering.

Check and common mistake. Each route has 3 points, and each has an x-range of 20 units. The vertical ranges differ as calculated above. A common mistake is to sort the legend labels alphabetically but leave the color and symbol vectors in their original order. That produces a plausible-looking legend with incorrect group labels; verify each label against the exact appearance used for that group.

Practical Checks Before Interpreting the Figure

A grouped scatterplot is useful only if its encodings survive scrutiny. Before describing patterns, check the following:

  • Axes: both variables are quantitative, and labels state what is measured and in which units.
  • Group mapping: each category has a distinct, consistent color or symbol, and the legend matches the points.
  • Comparability: all groups share the same axes and scale.
  • Coverage: the number of records in each group is known, so a dense-looking group is not mistaken for a larger one without checking its count.
  • Overlap: identical or nearly identical coordinates may make some group memberships hard to see.
  • Interpretation: describe the observed group patterns without converting a visual association into a causal claim.

When groups overlap heavily, do not claim that the plot proves a group is absent from a region just because its symbol is not visible there. Check the underlying records or counts, and consider a display adjustment that makes overlap clearer. When there are too many groups for distinct symbols or colors to remain readable, a single overlaid plot may not be the right display; the immediate priority is an honest, legible comparison rather than using every available visual attribute.

Grouped symbols add a categorical dimension to a scatterplot without changing the measurements on its axes. The essential discipline is to keep the mapping consistent, compare patterns within groups, and distinguish what the data contain from what the drawn marks happen to reveal. This visualization practice is aligned with the SOA Exam PA (Predictive Analytics) syllabus.

Check Your Understanding

For each problem, identify the group mapping and interpret the plotted information carefully.

  1. A hypothetical service study plots wait time against number of requests, distinguishing Email with blue circles and Phone with red triangles. What variable belongs on the symbol legend, and which variables belong on the axes? (Answer: Service channel belongs in the legend; number of requests and wait time are the two quantitative axis variables.)
  2. Group A has points (1, 4), (2, 6), and (3, 8); Group B has (1, 7), (2, 7), and (3, 7). What is the change in y from the first to last listed point for each group? (Answer: Group A increases by 4; Group B changes by 0.)
  3. A plot uses different symbols for two groups. Group A has (5, 10), (7, 12), and Group B has (5, 10), (9, 13). How many records and distinct coordinate locations are there? (Answer: 4 records and 3 distinct locations.)
  4. An R plot maps North to blue circles and South to orange triangles, but the legend lists North with orange triangles and South with blue circles. What is the problem, and what must be corrected? (Answer: The legend mapping is reversed; make its colors and symbols match the plotted group assignments.)
  5. Three groups have vertical ranges North 2–6, South 7–9, and West 3–4. Which has the largest vertical range, and what are the three range widths? (Answer: North is largest; the widths are North 4, South 2, and West 1.)
Clinical Biostats