R Data Visualization Recipes
上QQ阅读APP看书,第一时间看更新

How it works...

Step 1 defines ggplot with a set of different colors and shapes coming from the Species column in the data frame. Notice that most of it is asking for a scatterplot just like Recipe Plotting a basic scatterplot. By simply declaring two extra aesthetics (shape and colour) after the variable Species we've got points' colors and shapes tweaked.

It's important to outline that both arguments were named inside aes() function. We did this because values inputted were coming from a data frame variable. Other values could be named outside aes(). These aesthetics can be declared either by ggplot() or geom_point() function.

Step 2 conducts a similar change using plotly. To promote such change, the only requirement is to set the symbol argument after ~Species; hence, each different value coming from that variable will refer to a different color and shape by the time the plot is drawn.

Next, step 3 does about the same using ggvis.  To attach new shapes, trust shape argument. The colors are given by the fill argument. For both ggvis and plotly, variables coming from the data are named after the ~ sign. For ggplot2, arguments can be named after data frame variables by using aes() function.