Why ggplot2?

Learn what ggplot2 is and its application of the grammar of graphics.

There are two common ways to create plots in R: the plotting functions provided in base-R and ggplot2. Of course, other libraries and methods exist, but these two are the most common. There’s an ongoing debate about which of the two methods is better, and many R users continue to stick to base-R’s plotting methods. However, we’ll focus on developing skills in ggplot2.

Press + to interact
The ggplot2 logo
The ggplot2 logo

Benefits of ggplot2

There are two significant reasons to delve straight into ggplot2. The first is that it works very well in tandem with the tidyverse. If we’re already comfortable with the tidyverse, many of the lessons learned there will transfer well into ggplot2. The most significant similarity between ggplot2 and the tidyverse is that they’re both based on a strict underlying philosophy that allows functions and the code within to speak to each other quickly, and that minimizes the number of different rules and structures that coders need to keep in mind. So, whereas in the tidyverse, we have tidy data, in ggplot2, we have the “grammar of graphics.” ...