The purpose of this post is to show how to use the basic syntax of ggplot2, do some of the most common types of plots, as well as some customizations and facets. For this post we are going to use the iris dataset, as well as the skimr and cowplot packages. The first step consists of loading the desired packages, as well as the data and skimming over it. The first section will show some basic plots, while the next ones will show how to customize certain elements of the plots, like color, fill, facets and theme.
Then we can start building our different plots.
Basic plots
Scatterplot
Scatterplot.
Line plot
Line plot
Bar plot
Bar plot.
Column plot
Column plot.
Box plot
Boxplot.
Histogram plot
Histogram plot.
Adding colors
Color
Scatterplot with colors by factor.
Fill
Barplot with fill by factor.
Customized colors
Manual colors
Scatterplot with manual colors by factor.
Rcolorbrewer
Scatterplots with colors set by RColorbrewer.
Axes
Axes
Scatterplot with customized axes.
Axes labels
Scatterplot with customized axes labels.
Facets
Facet grid
Scatterplot with facets set as a grid.
Facet wrap
Scatterplot with facets set as a wrap (multiple factors will be accumulated by each panel).
Theme
Personalized theme
Scatterplot with facet wrap where several theme elements have been customized according to personal criteria.
Cowplot theme
Scatterplot with facet wrap where several theme elements have been customized according to the cowplot theme.