CO2 Emssions for 26 countries

We will use plotly to plot “emissions” data set, which is listing GDP, GDP per capita, and CO2 emissions for 1999.

data(emissions)
summary(emissions)
##       GDP            perCapita          CO2        
##  Min.   :  59900   Min.   : 2507   Min.   :  54.0  
##  1st Qu.: 123100   1st Qu.:13393   1st Qu.:  77.0  
##  Median : 206250   Median :20993   Median : 200.0  
##  Mean   : 830427   Mean   :17724   Mean   : 669.4  
##  3rd Qu.: 683500   3rd Qu.:22250   3rd Qu.: 547.5  
##  Max.   :8083000   Max.   :29647   Max.   :6750.0

Process the data

countryName <- rownames(emissions)
em <- cbind(countryName, emissions)
rownames(em) <- NULL
em
##      countryName     GDP perCapita  CO2
## 1   UnitedStates 8083000     29647 6750
## 2          Japan 3080000     24409 1320
## 3        Germany 1740000     21197 1740
## 4         France 1320000     22381  550
## 5  UnitedKingdom 1242000     21010  675
## 6          Italy 1240000     21856  540
## 7         Russia  692000      4727 2000
## 8         Canada  658000     21221  700
## 9          Spain  642400     16401  370
## 10     Australia  394000     20976  480
## 11   Netherlands  343900     21755  240
## 12        Poland  280700      7270  400
## 13       Belgium  236300     23208  145
## 14        Sweden  176200     19773   75
## 15       Austria  174100     21390   80
## 16   Switzerland  172400     23696   54
## 17      Portugal  149500     15074   75
## 18        Greece  137400     12833  125
## 19       Ukraine  124900      2507  420
## 20       Denmark  122500     22868   75
## 21        Norway  120500     27149   56
## 22       Romania  114200      5136  160
## 23 CzechRepublic  111900     10885  150
## 24       Finland  102100     19793   76
## 25       Hungary   73200      7186   85
## 26       Ireland   59900     16488   63

Including Plots

You can also embed plots, for example:

p <- plot_ly(em, x = ~countryName, y = ~GDP/100, type = 'bar', name = 'GDP') %>% 
            add_trace(y = ~perCapita, name = 'perCapita') %>% 
            add_trace(y = ~em$CO2, name = 'CO2')  %>%
            layout(yaxis = list(title = " GDP - Per Capita- CO2 emissions"), barmode = 'stack', autosize = F, width = 700, height = 700)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
p