Hi, I hope your family to be ok.
In this ocassion I´m going to show how an interactive plot looks in a web page of R Markdown. This is a perfect opportunity to show the skills that we have been acquiring during this specialization. The plot will be made with Plotly tools, this is amazing for me.
I´m going to read data from a web page of my interest, the graph shows a historical comparison between total CO2 emissions vs CO2 emission ought to oil.
rq = read_html("https://datosmacro.expansion.com/energia-y-medio-ambiente/emisiones-co2/colombia")
tb = html_nodes(rq, xpath = '//table[@id="tb"]')
df = html_table(tb) %>% as.data.frame()
head(df)
## Fecha CO2.Totales..Kts CO2.Petroleo.Kts CO2.Kg.1000. CO2.t..per.capita
## 1 2018 90.045 NA 0,14 1,82
## 2 2017 86.233 48.142 0,13 1,76
## 3 2016 88.419 47.050 0,14 1,82
## 4 2015 79.533 44.129 0,13 1,65
## 5 2014 79.674 46.720 0,13 1,67
## 6 2013 77.656 45.733 0,13 1,64
fig <- plot_ly(df, x = ~Fecha) %>% layout(title="Historical CO2 Emissions in Colombia")
fig <- fig %>% add_trace(y = ~CO2.Totales..Kts, type = "scatter", name = 'Total CO2 Emissions',mode = 'lines+markers')
fig <- fig %>% add_trace(y = ~CO2.Petroleo.Kts, type = "scatter", name = 'Oil CO2 Emissions', mode = 'lines+markers')
fig
Note: If we don´t change our habits and our way to generate what we consume, the planet is going to die. ¡Overheating!