Plotting a scatterplot with shapes and colors
There are several aesthetics coming out from geom_points()
that can be changed. Typing ?geom_point
into the R console will take you to the function documentation, which comes with a complete list of aesthetics understood by the function. The mandatory ones come in bold.
Names given are nothing but self-explanatory. Besides the mandatory x
and y
values, optional values range from alpha
to stroke
. For this particular recipe, we're settling for changes in the shape
and colours
arguments. Recipe also aims for similar results using both ggvis
and plotly
.Â
How to do it...
- Change theÂ
shape
andcolour
arguments to get a better result:
> library(ggplot2) > sca1 <- ggplot(data = iris, aes(x = Petal.Length, y = Petal.Width)) > sca1 + geom_point(aes(shape = Species, colour = Species))
Now each iris species is designated by a unique combination of shapes and colors:
Figure 2.3 - Adding shapes and colors to a scatter plot.
plotly
can also handle such...