When we think about Biostatistics we usually have in mind some more or less complex modelling examples such as linear models, generalized linear models, etc. However, part of our job is to report our results to non biostatistical collaborators and we need to be able to explain and talk about them. To do this, a great tool sometimes “forgotten”, are graphics.
In the last decades the R – Project for Statistical Computing (known as R) software has grown more than any other, thanks to contributions (packages) that researchers around the world share with the rest of the scientific community. One of the highlights of R is its versatility and customization for performing graphics.
If you are reading these lines the probability that you know how to plot with R using base graphics like plot(), barplot(), hist (), etc., is very high. My intention in this post is to present two packages that can radically change the look of our graphics making them more professional and nice-looking. The name of packages are lattice and ggplot2, both focus mainly on multivariate data but are flexible and support univariate data also.
Here is a self-explanatory description of lattice by its author: “Lattice is a powerful and elegant high-level data visualization system, with an emphasis on multivariate data, that is sufficient for typical graphics needs, and is also flexible enough to handle most nonstandard requirements”.
Lattice uses a simple code very similar to the syntax in base graphics and supports 3D plots. There is a very interesting book on it called Lattice: Multivariate Data Visualization with R written by Deepayan Sarkar.
With regard to ggplot2, the author describes it as: “a plotting system for R, based on the grammar of graphics, which tries to take the good parts of base and lattice graphics and none of the bad parts. It takes care of many of the fiddly details that make plotting a hassle (like drawing legends) as well as providing a powerful model of graphics that makes it easy to produce complex multi-layered graphics”.
Ggplot2 uses a special syntax to construct the graphics showing an interesting way to think about plots based on the book The Grammar of Graphics by Leland Wilkinson. The creation of plots is layer by layer. By default the plots are very elegant, sober and professional, but it also allows for high customization (when the syntax is known). It doesn’t support 3D plots though. It has a website to document and explain the package and it is worth mentioning the book ggplot2: Elegant Graphics for Data Analysis by Hadley Wickham.
To know more about lattice and ggplot2, I would recommend reading the exhaustive comparative in several posts on Learning R, starting with this one. Now it is your turn to check all this, you will love it!!!