7 October 2016

Background

  • This file is created to demonstrate the use of the HTML Markdown and the Plotly Package
  • The plot_geo function of the plotly package is used
  • The data used here is the Happiness Score by Country from the World Happiness Report 2016
  • The score of the Happiness index is associated with the color for each country- darker shade connotes a higher score

Slide with R Output

Here is the code used to generate the chart

library(plotly)
df <- read.csv('Happiness2015LogGDP.csv')
# light grey boundaries
l <- list(color = toRGB("grey"), width = 0.5)
# specify map projection/options
g <- list(showframe = FALSE,showcoastlines = FALSE,
          projection = list(type = 'Mercator'))
plot_geo(df) %>%add_trace(
  z = ~Score, color = ~Score, colors = 'Blues', 
  text = ~Country, locations = ~Code, marker = list(line = l)) %>%
  colorbar(title = 'Index') %>%
  layout(title = 'Happiness Score <br>Source:
         <a href="http://worldhappiness.report/ed/2016/">
         World Happiness Report</a>',geo = g)

Slide with Plot