On Linux, install the R development package, usually called r-devel or r-base-dev.
Install devtools by running install.packages("devtools") in R.
Install and Load ezplot
Get data. Notice we pass the url of the data directly to read.csv().
The dataset has a variable called Name that contains the names of the NBA players. By default, it’s read into R as a Factor with levels ordered alphabetically.
Reorder the levels of Name by the points each player scored.
The other variables are various performance statistics. To visualize the data in a heat map, we first need to put the data in the long format. In other words, we need to gather the names of the statistics in one column, and their actual values in another column.
Change dataset to long format.
In order to correctly display the information, we need to scale the values so that they are between 0 and 1. And we do that for each performance statistics. (After you finish reading, I encourage you to make a heat map using the unscaled values, and compare it with the scaled version. You will see the two heatmaps you get look very different. The scaled version is the correct one. To find out why, you can look up how heatmap is made in ggplot2 by looking up its source.)
Scale the values of each performance statistics.
With all the data prep work done, we’re ready to make a heatmap. This is super easy with the aid of ezplot.
Make a heat map.
By default, the heatmap we get uses the gray theme (Type ?theme_gray() to learn more). We can also make a heatmap using minimal theme by setting use_theme_gray=F.
Make a heat map using the minimal theme.
We can also change the size of the tick text on both axes.
Change tick text to 10 (default is 12).
I created ezplot because there are too many detailed commands to remember when customizing a ggplot. I hope ezplot can improve your productivity and make your data analysis work easier. If you’ve enjoyed using it, please spread the word. I’m writing a book called ezplot: How to Easily Make ggplot2 Graphics for Data Analysis, and it is 20% complete. Read the sample chapters for FREE and get notified when the book is published.