Skip to content

Instantly share code, notes, and snippets.

@JoFAM
Created February 12, 2019 11:01
Show Gist options
  • Save JoFAM/137248885d13eb120e95d2d3064f69a3 to your computer and use it in GitHub Desktop.
Save JoFAM/137248885d13eb120e95d2d3064f69a3 to your computer and use it in GitHub Desktop.
Small script to create a simulation of linear sealevel rise under different speeds.
library(tidyr)
library(ggplot2)
# I look at 4 different rates here. The rate for the period 2000-2018 was approximately 3 mm / year.
rates <- c(0.15,0.2,0.3, 0.4)
# This creates a tibble (dataset) with the sea level rise until 2100 depending on the rate
mydata <- tibble(
years = seq(2018,2100, by=1),
slow = seq_along(years)*rates[1],
medium = seq_along(years)*rates[2],
fast = seq_along(years)*rates[3],
lightning = seq_along(years)*rates[4]
) %>%
gather(key="tempo", value="increase",slow,medium,fast,lightning) %>%
mutate(tempo=factor(tempo,
levels = rev(c('slow','medium','fast','lightning')),
labels = rev(c("1.5 mm/y", "2 mm/y", "3 mm/y", "4 mm/y"))))
# This creates the plot
ggplot(mydata,aes(x=years,y=increase, fill=tempo)) +
geom_area(position = "identity", alpha = 0.8) +
geom_hline(yintercept = 10, col = "red", lwd = 1) +
geom_segment(x=2050, xend = 2050, y= 0, yend = 10) +
geom_segment(x=2085, xend = 2085, y= 0, yend = 10) +
labs(y="Increase in cm") +
ggtitle("Total sea level rise with different (linear) speeds")
@JoFAM
Copy link
Author

JoFAM commented Feb 12, 2019

The result :

sealevelsimulation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment