ggplot2 is an R package for producing statistical, or data, graphics, but it is unlike most other graphics packages because it has a deep underlying grammar. This grammar, based on the Grammar of Graphics (Wilkinson, 2005), is made up of a set of independent components that can be composed in many different ways. This makes ggplot2 very powerful because you are not limited to a set pre-specified graphics, but you can create new graphics that are precisely tailored for your problem.

— Hadley Wickham, ggplot2, 2016



As you may understand from the author’s words, ggplot2 is an R package written specifically to help you make graphs and charts in R, in a way that makes the coding more comprehensible.

That being said, let’s be fair and say that you do not NEED to use ggplot2 to create proper graphs in R. The built-in R base graphics are good enough, and if you have learned R base and understood the code and its details, arguments, parameters, you will certainly get the graph you want with not too much effort.

So why should we convince you to use ggplot2 instead of R base graphics? Well, we are not going to (try to) convince you. There is already a long debate about why to use ggplot2 vs. R base, and you may find good or bad arguments here and there. Instead of that, we are going to look at the basics of ggplot2, and learn how to use it to create simple graphs and charts. Then you will decide on your own whether you like it or prefer R base graphics.