Graphics Programs Reference
In-Depth Information
CrEATE ChErNoFF FACES
Go back to the basketball data, which represents the top 50 scorers in
the NBA, during the 2008-2009 season. There will be one face per player.
Don't worry—you don't have to create each face manually. The aplpack in R
provides a faces() function to help get you to where you want.
The newest
version of the
aplpack lets you
add color with the
faces() function.
In this example,
you set ncolors to
0 to use only black
and white. See
?faces to see how
you can use color
vectors in the
same way you
used them with
the previous
heatmap example.
If you haven't already, go ahead and install aplpack with install.packages()
or via the Package Installer. The package name stands for “another plot-
ting package” in case you were wondering, and it was designed by Hans
Peter Wolf. When installed, the package is usually automatically loaded,
but if not, you should do that, too.
library(aplpack)
You should have also already loaded the basketball data while creating a
heatmap. If not, again use read.csv() to load the data directly from a URL.
bball <- read.csv(“http://datasets.flowingdata.com/ppg2008.csv”,
header=TRUE)
After you load the package and data, it's straightforward to make Chernoff
Faces with the faces() function, as shown in Figure 7-10.
faces(bball[,2:16], ncolors=0)
Your dataset has 20 variables, plus player names; however, the faces()
function offered by the aplpack enables only a maximum of 15 variables,
because there are only so many facial features you can change. This is why
you subset the data on columns 2 to 16.
What does each face represent? The faces() function changes features in
the following order, matching the order of the data columns.
1. Height of face
2. Width of face
3. Shape of face
4. Height of mouth
5. Width of mouth
6. Curve of smile
7. Height of eyes
8. Width of eyes
9. Height of hair
10. Width of hair
11. Styling of hair
12. Height of nose
13. Width of nose
14. Width of ears
15. Height of ears
Search WWH ::




Custom Search