Global Temperature anomaly

Column

Figure 1. Global Temperature anomaly through the Years

Column

Global Warming

Global warming has in recent years become an increasingly topical issue. Global temperature anomaly has increased positively in the last several years as shown by the graph on the left (Figure 1). This strongly suggests a pattern towards global warming. There is need to inquire if

  1. The apparent global warming has an effect on the precipation of the local climate.
  2. Even if there could be daily records set on precipitations, is there an impact on the yearly precipitation patterns
  3. Does the precipitation changes vary significantly at different locations

To this end I have presented a Global warming anomaly graph in figure 1 and the yearly average precipitation of the cities of Seattle and Toronto to visually see if there is any long term effect due to the global warming.

Average yearly Precipitation for seattle and Toronto

Column

Figure 2. Seattle yearly average precipitation

Column

Figure 3. Toronto yearly average precipitation

---
title: "Lab2 - Data Exploration and Analysis Laboratory"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source_code: embed
  
---

```{r setup, include=FALSE}
library(flexdashboard)

```

Global Temperature anomaly
===========================================

Column {data-width=650}
-----------------------------------------------------------------------

### Figure 1. Global Temperature anomaly through the Years

```{r, echo=FALSE}

# data from https://www.ncdc.noaa.gov/cag/global/time-series/globe/land_ocean/1/2/1880-2019.csv

gta <- read.csv("Global_Temp_Anomaly.csv")

#Plot
library(ggplot2)
ggplot(gta, aes(x = Year, y =Value)) +
  geom_bar(aes(fill = Value < 0), stat = "identity") +
  scale_fill_manual(guide = FALSE, breaks = c(TRUE, FALSE), values=c("firebrick1", "steelblue")) +
  ggtitle("Global Temperature anomaly")

```

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

### Global Warming 

Global warming has in recent years become an increasingly topical issue. Global temperature anomaly has increased positively in the last several years as shown by the graph on the left (Figure 1). This strongly suggests a pattern towards global warming. There is need to inquire if 

1. The apparent global warming has an effect on the precipation of the local climate.
2. Even if there could be daily records set on precipitations, is there an impact on the yearly precipitation patterns
3. Does the precipitation changes vary significantly at different locations

To this end I have presented a Global warming anomaly graph in figure 1 and the yearly average precipitation of the cities of Seattle and Toronto to visually see if there is any long term effect due to the global warming.



Average yearly Precipitation for seattle and Toronto
=====================================================

Column {data-width=550}
-----------------------------------------------------------------------

### Figure 2. Seattle yearly average precipitation

```{r, echo=FALSE}
# Data from https://www.kaggle.com/rtatman/did-it-rain-in-seattle-19482017#seattleWeather_1948-2017.csv

seattle <- read.csv("seattleWeather_1948-2017.csv")

# subset data by year
library(stringr)
library(dplyr)

seattle$Year_ <- str_sub(seattle$DATE,-4,-1)
seattle$Year_  <- as.integer(seattle$Year_)

#  create a table grouped by Years, and then summarise each group by taking the mean of Precipitation

  # SYAV is the yearly average precipitation for Toronto
SYAV <- seattle %>% 
         group_by(Year_) %>%
         summarise(avg_precipitation = mean(PRCP, na.rm=TRUE))

# make 'year' variable to date format by concatenating the string '12-31 for December 31st
SYAV$day_month <- "12-31"
new_SYAV <- SYAV %>% mutate(yeardate=paste0(Year_, "-", day_month))
new_SYAV$yeardate <- as.Date(new_SYAV$yeardate)

#plot
ggplot(new_SYAV, aes(yeardate, avg_precipitation)) +
  geom_line() +
  stat_smooth(color = "#FC4E07", fill = "#FC4E07",  method = "loess") +
  xlab("years") +
  ylab("average precipitation") +
  ggtitle("Seattle average Precipitation")


```



Column {.tabset}
-----------------------------------------------------------------------

### Figure 3. Toronto yearly average precipitation

```{r, echo=FALSE}

# Data from https://www.kaggle.com/rainbowgirl/climate-data-toronto-19372018

toronto <- read.csv("Toronto_temp.csv")
toronto$Year <- as.character(toronto$Year)
toronto$Year <- as.integer(toronto$Year)

#  create a table grouped by Years, and then summarise each group by taking the mean of Precipitation
  # TYAV is the yearly average precipitaion for Toronto
TYAV <- toronto %>% 
        group_by(Year) %>%
        summarise(avg_precipitation = mean(Total.Precip..mm., na.rm=TRUE))

# make year variable in date format by concatenating the string '12-31 for December 31st
TYAV$Year <- as.character(TYAV$Year)
TYAV$day_month <- "12-31"

new_TYAV <- TYAV %>% mutate(yeardate=paste0(Year, "-", day_month))
new_TYAV$yeardate <- as.Date(new_TYAV$yeardate)

#plot
ggplot(new_TYAV, aes(yeardate, avg_precipitation)) +
  geom_line() +
  stat_smooth(color = "#FC4E07", fill = "#FC4E07",  method = "loess") +
  xlab("years") +
  ylab("average precipitation") +
  ggtitle("Seattle average Precipitation")

```