The outcome of the Global Gas Model (GGM) is processed in a R Script in order to generate some visualization tools. The general workflow is structured as follows:

Preparation for use of the script

Follow steps 1-9 for generating plots with R to visualize GGM results.

  1. Install R and R Studio
  2. Download the provided .zip directory
  3. Open the project file WorldMaps_ProjectFile.Rproj (R Studio will open)
  4. From there, open the data_file_generation_maps.R and plot_design_characteristics.R.
  5. Run the two scripts by Ctrl + Alt + R 1. Execution is finished showing “End of execution” in the Console
  6. For plots: open static_plots_REGIONS.R and static_plots_Europe.R
  7. Run the code with Ctrl + Alt + R 2. Execution is finished showing “End of execution” in the Console
  8. No errors? Perfect!! / Errors? the web might find a solution
  9. Check the folder Plots for files. You will find all plots and maps here (13 files).

Once the code executes without problems, new input data can be used. In order to do so, overwrite the .csv files rep_geo_map2.csv (for consumption and production) and rep_geo_map_flow (for trade).

Attention: Never remove countries_middle_lat_lon.csv and geo_data.csv only replace with same type of information and structure if necessary.

General information

This readme provides a short guide through the files for creating several kinds of plots that visualize the GGM’s output. The files needed for plot creation are the following:

Before the explanation of the different files follows, a short summary on changes that could become necessary is provided. Any question that can be answered with yes leads to the file where changes need to be performed.

INPUT

OUTPUT

Data preparation

Information for files data_file_generation_maps.R and plot_design_characteristics.R

Data frame generation

The file data_file_generation_maps.R takes the GGM output reports and creates data frames that are structured such that they can be used for creating maps and plots. The file contains three sections. 1. Data load of the raw data. 2. Creation of data frames for Europe 3. Creation of data frames for the different world regions used in the model

Important code chunks will be explained in the following. Whenever a comment is not above a code line but moved to the right, this highlights a line that can be changed if any of the questions above is answered with yes.

Raw data

Raw data is loaded from a GAMS output file and organised in the right shape. The first line is skipped and the separator declared as “,”. Columns that aggregate expansion capacities over year will be removed, other files/scenarios appended and all missing values replaced by 0. This is repeated for all files.

raw_data <- read.csv(
  "rep_geo_map2.csv",         # name of the file
  header = T,
  stringsAsFactors = F, 
  skip = 1,                   # first line is skipped
  sep = ","                   # declaration of separator
  ) %>% 
  dplyr::select(-starts_with("expcum")) %>%
  # appends rows from other scenarios (DUPLICATE/REMOVE)
  #bind_rows(                      # can be removed or duplicated
  #  read.csv(
  #    "rep_geo_map_NPS.csv",      # name of the file
  #    header = T,
  #    stringsAsFactors = F, 
  #    skip = 1,                   # first line is skipped
  #    sep = ","                   # declaration of separator
  #  ) %>% 
  #    dplyr::select(-starts_with("expcum")) 
  #) %>%

  mutate_all(list(~replace(., is.na(.), 0)))
  )

In addition, a function naming to rename the columns is introduced. This function takes a vector of repeating column names, a start-year and an end-year. The function moves in 5-year steps between start and end-year and appends attaches the year to the vector. Start and end have to be entered when calling the function. The following declarations might change if GGM output is adjusted.

columnnames <- c(       # this can look different if GAMS report changes
  "Cons", 
  "Prod", 
  "Trade", 
  "LNG", 
  "Pipe", 
  "Exp-P+", 
  "Exp-P-", 
  "Exp-L", 
  "Exp-R", 
  "Exp-Stor") %>%
  #NUMBER OF YEARS MUST BE ADJUSTED HERE! naming(start-year, end-year)
  naming(2015, 2025)    # define time horizon of GAMS report

columnnames1 <- c(
  "Scen","RGN", "CN",   # names of the first three columns
  columnnames           
  )  

In order to retrieve the full names of the region, a data frame is build with the necessary information. If the GGM regions change, please change this data frame.

regions <- data.frame(       # might change if GGM regions change
  c(
    "SAM", "NAM", "EU", 
    "ROE", "AFR", "ASP", 
    "MEA", "CAS", "RUS"
    ),
  c(
    "South America",
    "North America", 
    "European Union",
    "Rest of Europe",
    "Africa", 
    "Asia Pacific",
    "Middle East Asia",
    "Caspian Region",
    "Russia"
    ), 
  stringsAsFactors = FALSE
  ) 

At the end of this section, the raw data is saved in a work space for further use.

Europe

For Europe, two data frames are necessary for visualization. One to create column charts and one for an interactive map.

plot_data_EU serves as input for any column chart. In order to create this data frame, the raw data is filtered for regions in Europe (EU and ROE), consumption and production data is selected and geographical data (latitude, longitude and full name) is added. The structure changes when calling gather: capacity is now specified by type (which represents the earlier column names). A separation created a new column with the year.

plot_data_EU <- raw_data %>%
  filter(RGN=="EU" | RGN== "ROE") %>%
  dplyr::select(               # adjust selection for different graphs
    1:3, 
    starts_with("Cons"), 
    starts_with("Prod")
    ) %>%
  left_join(geo_data_EU, by="CN") %>%
  gather("Type", "Capacity", 4:(length(.)-4)) %>% 
  separate(Type, into=c("Type", "Year"), sep = "_") 

The final structure looks as follows

## 'data.frame':    396 obs. of  10 variables:
##  $ Scen     : chr  "SDS-Vision" "SDS-Vision" "SDS-Vision" "SDS-Vision" ...
##  $ RGN      : chr  "EU" "EU" "EU" "EU" ...
##  $ CN       : chr  "AUT" "BEL" "BGR" "CYP" ...
##  $ iso2     : chr  "AT" "BE" "BG" "CY" ...
##  $ latitude : num  47.5 50.5 42.7 35.1 49.8 ...
##  $ longitude: num  14.55 4.47 25.49 33.43 15.47 ...
##  $ name     : chr  "Austria" "Belgium" "Bulgaria" "Cyprus" ...
##  $ Type     : chr  "Cons" "Cons" "Cons" "Cons" ...
##  $ Year     : chr  "2015" "2015" "2015" "2015" ...
##  $ Capacity : num  9.97 18.06 3.54 0 8.9 ...

plot_data_EU_2 is used for the interactive leaflet map. It moves the type back into columns but keeps the year. In addition, capacities are filtered such that only a limited number is shown in the map. A separation created a new column with the year.

plot_data_EU_2 <- spread(
  plot_data_EU, Type, Capacity
  ) %>%
  filter(Cons > 10.0 | Prod > 5.0)      # adjust for other countries on maps

World

Data frames for the world regions are created in the same way as for Europe. In addition, there is a third data frame for visualizing flows. plot_data_world_3 contains aggregated trade volumes for trade between different regions. A filter on trade volumes can be adjusted if more trade flows should be shown in the map.

Plot design

The file plot_design_characteristics.R allows for adjustments in the layout of all plots. Specification of the following attributes are generalized:

  • colors (categories for scenarios and capacities)
  • theme (background, grid)
  • fonts (size, colors)

Plot Generation

The files for Europe and World Regions comprise a set of plots that are automatically saved to the plots folder within the directory. The following plots are generated:

ggplot(
    # chose data
    data = filter(plot_data_EU, Type == "Prod" & Capacity > 0 & RGN == "EU"), 
    aes(reorder(name, Capacity), 
        y = Capacity, fill = Scen)
    ) +
  geom_bar(stat = "identity", position = "dodge", width = 1) +
  # add colour according to fill variable
  scale_fill_manual(values = col_scen, 
                    name = "Scenario" 
  ) +
  # title and axis labels
  labs(title = "Gas production pattern for European Union in two scenarios", 
       x = "Country", 
       y ="Production in bcm per year") +
  fonts +
  theme_plot +
  coord_flip() +
  facet_wrap(~Year) 

plot_data_EU %>%
  group_by(Scen, Type, Year) %>%
  summarise(Capacity = sum(Capacity)) %>% 
  ungroup() %>%
  filter(Type != "Trade")%>%
  ggplot(aes(
    x = Year, y = Capacity, 
    colour = Type, shape = Scen, 
    group = interaction(Type, Scen))
    ) + 
  geom_line(aes(color = Scen),size=1) +
  geom_point(aes(shape = Scen),size=2) +
  theme_plot+
  scale_colour_manual(values = rep(col_cap, times=2), 
                      name = "Capacity of", 
                      labels=c(
                        "consumption in \nSDS-Vision", 
                        "production in \nSDS- Vision", 
                        "consumption in \nsecond", 
                        "production in \nsecond"
                        )
  ) +
  #fonts +
  labs(title = "Europe outlook on total production and consumption of gas",
       y = "Capacity of Gas in bcm",
       shape = "Scenario"
       ) +
  ylim(0,600)

If there is a wish to change any layout or visualization methods, the script allows for changes in all attributes.

The last item within both files static_plots_REGIONS.R and static_plots_Europe.R is a loop that creates interactive maps using the leaflet package. The number of maps created equals the number of scenarios run in the model. These maps visualize bar plots for consumption and production in EU countries or world regions evolving over time. In addition, there is a visualization of trade flows for trade between world regions.


  1. This may take a while when executed for the first time. R will download and install all necessary packages.

  2. If only a chunk of the code needs to be run, mark the code and press Ctrl + Enter; for only one line, move the cursor to the line and press Run