ggpattern package in R is an extension of the ggplot2
package, designed to add pattern aesthetics to your
It allows you to add patterns like stripes, crosses, custom images and more to your ggplot2 plots, making your visualizations more informative and engaging.
✍️ author → Mike FC
📘 documentation → github
⭐️ more than 500 stars on github
This package can be especially useful if you need to publish some black and white content.
Getting started with
ggpattern is straightforward.
First, ensure you have
ggplot2 installed. Then, you can
ggpattern directly from CRAN using the
ggpattern package comes with a variety of
pattern aesthetics that can be easily integrated into
Let’s take an example with the
aesthetics. It does pretty much the same task as the
geom_col() aesthetics of
ggplot2 that is used
But it adds options to use some patterns into rectangles.
The aesthetics comes with a number of options described in the next section. For each, you have to decide:
if you want it to depend on a value of the dataset, put it inside
aes() call. Below, the color of the pattern is mapped
name columnn since
if you want it to be the same for all shapes, put it outside the
aes() call. For instance, all bars will be using
It is possible to customize pretty much everything on the pattern you are building.
fill control the shape
outline and the shape content colors.
pattern controls the pattern type. It can be:
‘stripe’ (default), ‘crosshatch’, ‘point’, ‘circle’ or ‘none’
pattern_alpha controls the pattern
pattern_angle controls the angle 🤷♀️
the outline and fill colors
help(geom_col_pattern) to get some more details on
all the available options!
You can map the pattern features to the data in use.
For instance, the following example use a very different look for
each group of the dataset. To do so, the arguments described above are
placed inside the
Several other aesthetics are available, allowing to fill any kind of
chart types with pattern. Names are always matching the original
To put it in a nutshell:
geom_boxplot_patterncan be used for boxplot
geom_density_patternfor density charts
geom_violin_patternfor violin charts
And many more are on the list. Here is an overview of other examples
in the gallery using the