Climate Change

Introduction

Climate change has been a huge environmental threat and likely one of the most important challenges of our time. Climate change may refer to a change in average weather conditions, or in the time variation of weather within the context of longer-term average conditions. To understand climate change, we used “rWBclimate” package to extract climate data from World Bank database to showcase the trend of global warming in Europe.

Dashboard


Annual Average Temperature in 20-year intervals

Column

Annual Average precipitation in mm

historical plot

Questions about Climate Change

1.How accurate is the model in predicting average temperature in the future?

2.Is there a significant relationship between average temperature and average precipitation?

3.What is the projected average temperature in 200 years? Is the result reliable?

---
title: "ANLY512 lab2"
author: Tian Zhu, Yumeng Du 
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    source_code: embed
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(knitr)
library(ggplot2)
library(dplyr)
library(plotly)
library(rWBclimate)
library(ggplot2)
library(devtools)
library(shiny)
library(shinydashboard)
```



###Climate Change


Introduction
===================================== 

Climate change has been a huge environmental threat and likely one of the most important challenges of our time. Climate change may refer to a change in average weather conditions, or in the time variation of weather within the context of longer-term average conditions. To understand climate change, we used “rWBclimate” package to extract climate data from World Bank database to showcase the trend of global warming in Europe. 

Dashboard
===================================== 
-----------------------------------------------------------------------

### Annual Average Temperature in 20-year intervals

```{r}
gbr.dat.t <- get_ensemble_temp("GBR", "annualavg", 1800, 2200)
## Loading required package: rjson
### Subset to just the median percentile
gbr.dat.t <- subset(gbr.dat.t, gbr.dat.t$percentile == 50)
gbr.dat.t$fromYear=as.numeric(gbr.dat.t$fromYear)
gbr.dat.t$toYear=as.numeric(gbr.dat.t$toYear)
gbr.dat.t$data=as.numeric(gbr.dat.t$data)
## Plot and note the past is the same for each scenario
ggplot(gbr.dat.t, aes(x=fromYear,y=data,group=scenario,colour=scenario)) +
 geom_point() +
 geom_path() +
 theme_bw() +
 xlab("Year") +
 ylab("Annual Average Temperature in 20 year intervals")
```

Column {data-width=350}
-----------------------------------------------------------------------

### Annual Average precipitation in mm

```{r}
gbr.dat.p <- get_ensemble_precip("GBR", "annualavg", 1800, 2200)
gbr.dat.p <- subset(gbr.dat.p, gbr.dat.p$percentile == 50)
gbr.dat.p$fromYear=as.numeric(gbr.dat.p$fromYear)
gbr.dat.p$toYear=as.numeric(gbr.dat.p$toYear)
gbr.dat.p$data=as.numeric(gbr.dat.p$data)
ggplot(gbr.dat.p, aes(x = fromYear, y = data, group = scenario, colour = scenario)) +
    geom_point() + geom_path() + theme_bw() + xlab("Year") + ylab("Annual Average precipitation in mm")
```

### historical plot

```{r}

gbr.modelpast <- subset(gbr.dat.t, gbr.dat.t$scenario == "past")
gbr.historical <- get_historical_temp("GBR", "year")
### Plot create historical plot
hist.plot <- ggplot(gbr.historical, aes(x = year, y = data)) + geom_point() +
    geom_path()

### Create a centroid for the past
gbr.modelpast$centroid <- round((gbr.modelpast$fromYear + gbr.modelpast$toYear)/2)

### Create averages based the same windows used in the model output for
### comparison
win_avg <- function(from, to, df) {
    win <- subset(df, df$year >= from & df$year <= to)

    return(c(mean(win$data), round(mean(c(from, to)))))
}
hist.avg <- matrix(0, ncol = 2, nrow = 0)
for (i in 1:dim(gbr.modelpast)[1]) {
    hist.avg <- rbind(hist.avg, win_avg(gbr.modelpast$fromYear[i], gbr.modelpast$toYear[i],
        gbr.historical))
}
colnames(hist.avg) <- c("data", "centroid")

### Create new dataframe of historical averages and model averages
hist.comp <- rbind(hist.avg, cbind(gbr.modelpast$data, gbr.modelpast$centroid))
hist.comp <- as.data.frame(hist.comp)
hist.comp$Output <- c(rep("Historical", 4), rep("Model", 4))

### overlay the averages with the original raw data plot
hist.plot <- hist.plot + geom_point(data = hist.comp, aes(x = centroid, y = data,
    colour = Output, group = Output, size = 3)) + geom_path(data = hist.comp,
    aes(x = centroid, y = data, colour = Output, group = Output)) + guides(size = FALSE)

hist.plot + xlab("Year") + ylab("Annual average temperature in deg C") + theme_bw()
```

Questions about Climate Change
====================================

1.How accurate is the model in predicting average temperature in the future?

2.Is there a significant relationship between average temperature and average precipitation?

3.What is the projected average temperature in 200 years? Is the result reliable?