O'Reilly logo

R Graphs Cookbook by Hrishi Mittal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Grouping data points within a scatter plot

A basic scatter plot has a set of points plotted at the intersection of their values along X and Y axes. Sometimes, we may wish to further distinguish between these points based on another value associated with the points. In this recipe we will see how we can group data points using color.

Getting ready

To try out this recipe, start R and type the recipe at the command prompt. You can also choose to save the recipe as a script so that you can use it again later on.

We will also need the lattice and ggplot2 packages. The lattice package is included automatically in the base R installation, but we will need to install the ggplot2 package. To do this, run the following command at the R prompt:

install.packages("ggplot2") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required