Background

Once you have produced a result from matilda there are a number of useful ways to visualize the data. We will cover some of those in a series of tutorials to help you plot Matilda results, including:

  1. Spaghetti plot - these are plots aimed to visualize the trajectories of all model iterations and the weights associated with each.

  2. Probability bar plot - these are stacked bar plots colored by variable ranges (e.g., temperature) used to compute probabilities in the matilda workflow.

  3. Probability with range distinction - these are similar to stacked bar plots but in the form of a probability distribution rather than a stacked bar.

  4. Median value with confidence ribbon - classic plotting technique for climate model projections.

This is Part 2 of the tutorial series and will cover the Probability Bar Plot!

library(matilda)
library(ggplot2)

Probability bar plot

The goal of this plot is to visualize the probabilities of a climate variable of interest falling within a given range (bin).

Data

If you are plotting in a session different from the original analysis, ensure you have the data needed to complete the plots.

For a probability bar plot we need at a minimum the probability results produced after running prob_calc. As a review, prob_calc uses metrics (computed with metric_calc), weights (computed with score_runs), and user specified bins in order to calculate the probability that the metric for any given run will fall within a bin range. In this example the metric used is the 10 year average global mean surface temperature anomaly and bins represent a temperature range.

The data should look something like this:

##       bins       scores  probability scenario
## 1  (1,1.5] 6.917474e-01 8.970021e-01   ssp119
## 2  (1.5,2] 7.941980e-02 1.029852e-01   ssp119
## 3  (2,2.5] 9.777507e-06 1.267868e-05   ssp119
## 4  (1,1.5] 2.386366e-04 2.386366e-04   ssp245
## 5  (1.5,2] 2.028253e-01 2.028253e-01   ssp245
## 6  (2,2.5] 5.425495e-01 5.425495e-01   ssp245
## 7  (2.5,3] 2.495259e-01 2.495259e-01   ssp245
## 8  (3,3.5] 4.850461e-03 4.850461e-03   ssp245
## 9  (4,4.5] 1.017587e-05 1.017587e-05   ssp245
## 10 (1.5,2] 2.409654e-04 2.409654e-04   ssp370

Plotting

All plotting will be completed using ggplot2. If you are unfamiliar with ggplot2 there are several well-written tutorials online.

The final plot from this tutorial will be horizontal bar plot where each bar represents the temperature probabilities for each SSP scenario we used to run our model. There are a number of freedoms that can be taken with respect to design we use a palette here that pairs with the 8 temperature ranges for which we computed probabilities (temp_ranges <- c(1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, Inf)).

Color palette:

library(scales)
temp_cols <- c("#2166AC","#4393C3","#D1E5f0","#FDDBC7","#F4A582","#D6604D","#B2182B","#67001F")
show_col(temp_cols)

In these plots the x-axis represents the probability (0-1) and the y-axis will represent the scenarios in question.

probability_plot <- 
  ggplot(data = plot_2_df, # identify the data location
         aes(
           fill = bins, # how fill should be applied
           x = scenario, # what data goes on the x-axis
           y = probability)) + # what data goes on the y-axis
  # below we will be flipping the coord of the figure so right now the axes seem 
  # backwards from what we want.
  geom_bar(position = position_fill(reverse = T), # what type of plot we want and reverse the 
                                                  # stack order so cooler temps are on left
           stat = "identity", # we want the width of the bar pieces to be constrained by a value in the data
           width = 0.6) + # how wide do you want the bar - personal preference
  scale_y_continuous(breaks = seq(0.0, 1.0, 0.1)) + # set the number and interval of probability breaks
  scale_fill_manual(
    values = temp_cols, # indicate the color palette to use
    labels = c(         # edit labels for the legend
      expression(paste("1.0 to 1.5", ~degree, "C")),
      expression(paste("1.5 to 2.0", ~degree, "C")),
      expression(paste("2.0 to 2.5", ~degree, "C")),
      expression(paste("2.5 to 3.0", ~degree, "C")),
      expression(paste("3.0 to 3.5", ~degree, "C")),
      expression(paste("3.5 to 4.0", ~degree, "C")),
      expression(paste("4.0 to 4.5", ~degree, "C")),
      expression(paste(" > 4.5", ~degree, "C"))),
    name = "Warming") + # name of the legend
  labs(y = "Probability",
       x = "Forcing Scenario", 
       title = "Probability of Warming") +
  coord_flip() + # flip the coordinates of the figure to make horizontal representation
  theme_light() + # set theme - personal preference 
  theme(legend.position = "bottom") # change legend position - personal preference

probability_plot

You can see how the plot separates our temperature range probabilities by color. The entirety of each bar = 1.0 and subsections of the bar (coded by our color palette) indicate the probability of any given temperature anomaly range.

For example, in SSP5-8.5 Matilda projects there is a ~50% probability that end of century (10 yr average) global mean surface temperature will be >4.0 C warmer compared to the pre-industrial reference period. Similarly, we can see that our results would suggest that under the SSP1-1.9 scenario there is a ~90% probability that end of century global mean surface temperature will only be warmer by 1-1.5 C. Note that these are simply examples and calculations here made a number of assumptions to simplify the results for this visualization exercise.