Graphics Reference
In-Depth Information
Figure 4-8. A sawtooth pattern indicates improper grouping
This happens because there are multiple data points at each ylocation, and
ggplot()
thinks
they're all in one group. The data points for each group are connected with a single line, leading
to the sawtooth pattern. If any discretevariables are mapped to aesthetics like
colour
or
line-
type
, they are automatically used as grouping variables. But if you want to use other variables
for grouping (that aren't mapped to an aesthetic), they should be used with
group
.
NOTE
When in doubt, if your line graph looks wrong, try explicitly specifying the grouping variable with
group
. It's common for problems to occur with line graphs because
ggplot()
is unsure of how the
variables should be grouped.
If your plot has points along with the lines, you can also map variables to properties of the points,