Plot multiple areas

Hi
I am new to 'R' so apologise in advance.
I have this Excel file data which contains data for:
1-base carbon emissions versus years
2- Post resource efficiency emissions (Post-REEE)
3- Abated emissions (after deploying decarbonisation technologies).

I want to plot them similar to the attached figure below such that the Post-REEE 'eats' from the base, then the abated 'eats' from the Post-REEE, is there please a way to do that please using R studio?

Many thanks

Please any suggestions? Thanks

Use the ggplot2 package to create this graph. Lookup geom_area() function from the ggplot2 package for this chart.

Your Excel file is in a non-tidy format (non-normalized data) so this is harder than it should be but it is doable, here a base plot you can customize as needed.

library(tidyverse)
library(readxl)

link <- "https://drive.google.com/uc?export=download&id=1rnhQfLAp-y-gB0AKHaVnd9UycwQL4ok2"

download.file(link, "data.xlsx")

Baseline <- read_xlsx("data.xlsx",
                     sheet = 1,
                     range = "D2:E36",
                     col_names = TRUE)

post_REEE <- read_xlsx("data.xlsx",
                     sheet = 1,
                     range = "H2:I36",
                     col_names = TRUE)

Abatement <- read_xlsx("data.xlsx",
                      sheet = 1,
                      range = "L2:M36",
                      col_names = TRUE)

list(Baseline, post_REEE, Abatement) %>% 
   set_names(nm = c("Baseline", "post_REEE", "Abatement")) %>% 
   map_dfr(.f = ~ .x, .id = "emision_type") %>% 
   mutate(emision_type = factor(emision_type, levels = c("Baseline", "post_REEE", "Abatement"))) %>% 
   ggplot(aes(x = years, y = emissions)) +
   geom_area(aes(fill = emision_type), position = 'identity')

Created on 2021-04-14 by the reprex package (v2.0.0)

2 Likes

Many thanks for you all

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.