3D histograms in R
In this post I am going to show you how to construct a beautiful 3D histogram that can be a very nice way to show your frequency data. For this, I will use the ggridges
package.
ggridges
The ggridges
package has functions to construct 3d histograms.
For this example we are going to load some data of the number of observations of Sentinel-2 1C images over different ecorregions in Mexico. Here’s an extract of that table, containing the frequency of pixels with number of valid observations (y2). The data was reduced to preserve the proportions with a smaller number of observations.
desc_id | year | month | labels | y2 |
---|---|---|---|---|
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 2 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 3 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 1 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 4 |
Selvas Calido Humedas | 2018 | 1 | 5 | 5 |
Selvas Calido Humedas | 2018 | 1 | 5 | 5 |
Selvas Calido Humedas | 2018 | 1 | 5 | 5 |
Selvas Calido Humedas | 2018 | 1 | 5 | 5 |
Selvas Calido Humedas | 2018 | 1 | 5 | 5 |
Selvas Calido Humedas | 2018 | 1 | 5 | 5 |
Selvas Calido Humedas | 2018 | 1 | 5 | 6 |
Selvas Calido Humedas | 2018 | 1 | 5 | 0 |
Then we will calculate the mean for the groups of interest (ecoregion, month and year) and join them to the original df.
Then we can create the 3d histogram with geom_density_ridges_gradient
and save it as jpeg.