GDP Growth by Sectors


https://rstudio.github.io/leaflet/

d3heatmap creates interactive D3 heatmaps including support for row/column highlighting and zooming.


https://github.com/rstudio/d3heatmap/

---
title: "Do GDP and Energy Consumption Cause Co2 Emission Increase?"
output: 
  flexdashboard::flex_dashboard:
    storyboard: true
    social: menu
    source: embed
---

```{r setup, include=FALSE,echo=TRUE}

library(tidyr)      #tidy unclean data into a clean 
library(dplyr)      #do data transformation, help format a needed dataframe
library(ggplot2)    #make elegant graphs
library(readr)      #import dataset into R
library(readxl)     #import Excel files into R
library(magrittr)   #pipe dataframe to functions
library(plotly)     #initiate a plotly visualization
library(flexdashboard)   #create interactive dashboards
library(DT)         #show dataframe in a nicer way

GDPCO2<- read.csv("GDPCO2.csv")
GDP <- GDPCO2[c(1:23),c(3,5:10,11,12,14:26)]
energy_sector <- read.csv("energy_sector.csv")
energy_sector1 <- energy_sector[-c(24:28),c(3,5,7:12,14,16,18,21,22,24,27,29)]
Total <- merge(GDP, energy_sector1, by = "Time")

write_csv(Total, "Total.csv")
Totaltable <- read.csv("Total.csv",
                 col.names = c("Time","Agriculture","GDP_per_capita","GDP","GDP_growth","Industry","Service","Population_growth","Population","CO2_transportp","CO2_gasp",
                               "CO2_solidp","CO2_solid","CO2_others","CO2_gas","CO2_manu_consp","CO2_elec_heatp",
                               "CO2_rcpp","CO2","CO2_liqp","CO2_per_capita_mt","CO2_agri","Biogas","Agricultural_MJ","Industrial_MJ","Residential_MJ","Service_MJ","Transportation_MJ","Geothermal","Hydro","Liquid_Biofuel","Marine","Renewable","Solar","TFEC","Solid_Biofuel","Wind"))

Totaltable2 <- Totaltable %>%
  transmute(
    Time = Time,
    Agriculture = Agriculture * GDP /100,
    Industry = Industry * GDP /100,
    Service = Service * GDP /100,
    Population = Population,
    GDP = GDP,
    CO2_transport = CO2_transportp * CO2,
    CO2_others = CO2_others * CO2,
    CO2_manu_cons = CO2_manu_consp * CO2,
    CO2_elec_heat = CO2_elec_heatp * CO2,
    CO2_rcp = CO2_rcpp * CO2,
    Agricultural_MJ = Agricultural_MJ * GDP,
    Industrial_MJ = Industrial_MJ * GDP,
    Residential_MJ = Residential_MJ* 1000 * Population / 3,
    Service_MJ = Service_MJ * GDP,
    Transportation_MJ = Transportation_MJ * GDP,
    TFEC = TFEC * 1000000,
    CO2 = CO2,
    Biogas = Biogas,
    Geothermal = Geothermal,
    Hydro = Hydro,
    Liquid_Biofuel = Liquid_Biofuel,
    Marine = Marine,
    Renewable = Renewable,
    Solar = Solar,
    Solid_Biofuel = Solid_Biofuel,
    Wind = Wind)
```

### GDP Growth by Sectors

```{r,message=F, warning=F, echo=FALSE}

p1 <- Totaltable2 %>% 
  gather(Sector, Amount, 2:4)%>%
  plot_ly(x = ~Time, y = ~Amount, color = ~Sector, type = 'scatter', mode = 'lines+markers', width = 8, height = 4)%>%
  layout(title = "GDP Contribution by Sector",
         xaxis = list(title = "Year"),
         yaxis = list(title = "GDP Value Added"))
p1

```

***

https://rstudio.github.io/leaflet/

- Interactive panning/zooming

- Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON.

- Create maps right from the R console or RStudio

- Embed maps in knitr/R Markdown documents and Shiny apps

- Easily render Spatial objects from the sp package, or data frames with latitude/longitude columns

- Use map bounds and mouse events to drive Shiny logic


### d3heatmap creates interactive D3 heatmaps including support for row/column highlighting and zooming.

```{r}
library(d3heatmap)
d3heatmap(mtcars, scale="column", colors="Blues")
```

***

https://github.com/rstudio/d3heatmap/

- Highlight rows/columns by clicking axis labels

- Click and drag over colormap to zoom in (click on colormap to zoom out)

- Optional clustering and dendrograms, courtesy of base::heatmap