8/23/2019

Introduction

  • This project was created as part of the Developing Data Products course of the Coursera Data Science Specialization.

  • The goal of the project is to create a web page presentation using R Markdown that features a plot created with plotly and to host the resulting web page on either GitHub Pages, RPubs or NeoCities.

Data Set We Are Using

Reading Data Set

head(gapMinder)
##       country year      pop continent lifeExp gdpPercap
## 1 Afghanistan 1952  8425333      Asia  28.801  779.4453
## 2 Afghanistan 1957  9240934      Asia  30.332  820.8530
## 3 Afghanistan 1962 10267083      Asia  31.997  853.1007
## 4 Afghanistan 1967 11537966      Asia  34.020  836.1971
## 5 Afghanistan 1972 13079460      Asia  36.088  739.9811
## 6 Afghanistan 1977 14880372      Asia  38.438  786.1134
dim(gapMinder)
## [1] 1704    6

Subsetting Data According To The Year 2007

data_2007 <- gapMinder[which(gapMinder$year == 2007),]
data_2007 <- data_2007[order(data_2007$continent, data_2007$country),]
data_2007$size <- data_2007$pop
colors <- c('#4AC6B7', '#1972A4', '#965F8A', '#FF7070', '#C61951')
head(data_2007)
##          country year      pop continent lifeExp  gdpPercap     size
## 36       Algeria 2007 33333216    Africa  72.301  6223.3675 33333216
## 48        Angola 2007 12420476    Africa  42.731  4797.2313 12420476
## 132        Benin 2007  8078314    Africa  56.728  1441.2849  8078314
## 168     Botswana 2007  1639131    Africa  50.728 12569.8518  1639131
## 204 Burkina Faso 2007 14326203    Africa  52.295  1217.0330 14326203
## 216      Burundi 2007  8390505    Africa  49.580   430.0707  8390505

Loading Libraries

library(plotly)
## Warning: package 'plotly' was built under R version 3.6.1
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout

R Code

showplot <- plot_ly(data_2007, x = ~gdpPercap, y = ~lifeExp, z = ~pop, 
                    color = ~continent,type = "scatter3d",mode="markers",size = ~size,
                    colors = colors,marker = list(symbol = 'circle', 
                    sizemode = 'diameter'),sizes = 16,text = ~paste('Country:',
                    country, '<br>Life Expectancy:',lifeExp, '<br>GDP:', 
                    gdpPercap,'<br>Pop.:', pop)) %>%
  layout(title = 'Life Expectancy v. Per Capita GDP, 2007',
         scene = list(xaxis = list(title = 'GDP per capita (2000 dollars)',
                      gridcolor = 'rgb(255, 255, 255)',
                      range = c(2.003297660701705, 5.191505530708712),type = 'log',
                      zerolinewidth = 1,ticklen = 5,gridwidth = 2),
                      yaxis = list(title = 'Life Expectancy (years)',
                      gridcolor = 'rgb(255, 255, 255)',
                      range = c(36.12621671352166, 91.72921793264332),
                      zerolinewidth = 1,ticklen = 5,gridwith = 2),
                      zaxis = list(title = 'Population',
                      gridcolor = 'rgb(255, 255, 255)',type = 'log',
                      zerolinewidth = 1,ticklen = 5,gridwith = 2)),
         paper_bgcolor = 'rgb(243, 243, 243)',plot_bgcolor = 'rgb(243, 243, 243)')

3D Bubble Plot

showplot