Plotting a basic scatterplot
Scatterplots play a major role in the representation of two continuous variables. Making simple scatterplots is a very easy task to handle using ggplot2
, ggvis
, or plotly
. This recipe uses a data frame called iris
to draw plots, it comes with base R (datasets
package).
Note
Before using data coming from a package, you may want to try entering ?<package name>::<data frame name>
into your console. For this recipe, that would go as: ?datasets::iris
. This is may lead you towards data documentation, this way you get to know each variable coming from the data frame.
From the various features presented by this data set, this recipe uses Petal.Width
and Petal.Length
. They respectively account for iris' petal widths and lengths measured in centimeters. Besides drawing the plots, this recipe also teaches how to add a title to them. So, move on to the coding!
How to do it...
- Initialize a
ggplot
 and then give it the point geometry:
> library(ggplot2) > sca1 ...