Introduction:

In this project, we will use a Kaggle dataset describing world couontries using different parameters to compare them. We will use only some of these parameters to create a Plotly 3D-Scatter plot comparing all the countries listed. We will make use of variuos Plotly features to create the plot in order to demonstrate some of Plotly numerous uses. There are many other features of the Plotly experience; however, every set of features only applies to other types of data.

Uploading Data:

library(readr)
library(plotly)
## 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
library(colorspace)
Kaggle <- read_csv("~/DataProducts/2/Kaggle.csv")
## Parsed with column specification:
## cols(
##   .default = col_double(),
##   Id = col_character()
## )
## See spec(...) for full column specifications.
head(Kaggle)
## # A tibble: 6 x 66
##   Id    `Human Developm~ `Gini coefficie~ `Adolescent bir~ `Birth registra~
##   <chr>            <dbl>            <dbl>            <dbl>            <dbl>
## 1 Norw~            0.944             26.8             7.83              100
## 2 Aust~            0.935             34.0            12.1               100
## 3 Swit~            0.930             32.4             1.9               100
## 4 Denm~            0.923             26.9             5.10              100
## 5 Neth~            0.922             28.9             6.16              100
## 6 Germ~            0.916             30.6             3.80              100
## # ... with 61 more variables: `Carbon dioxide emissionsAverage annual
## #   growth` <dbl>, `Carbon dioxide emissions per capita 2011 Tones` <dbl>,
## #   `Change forest percentable 1900 to 2012` <dbl>, `Change mobile usage
## #   2009 2014` <dbl>, `Consumer price index 2013` <dbl>, `Domestic credit
## #   provided by financial sector 2013` <dbl>, `Domestic food price level
## #   2009 2014 index` <dbl>, `Domestic food price level 2009-2014
## #   volitility index` <dbl>, `Electrification rate or population` <dbl>,
## #   `Expected years of schooling - Years` <dbl>, `Exports and imports
## #   percentage GPD 2013` <dbl>, `Female Suicide Rate 100k people` <dbl>,
## #   `Foreign direct investment net inflows percentage GDP 2013` <dbl>,
## #   `Forest area percentage of total land area 2012` <dbl>, `Fossil fuels
## #   percentage of total 2012` <dbl>, `Fresh water withdrawals 2005` <dbl>,
## #   `Gender Inequality Index 2014` <dbl>, `General government final
## #   consumption expenditure - Annual growth 2005 2013` <dbl>, `General
## #   government final consumption expenditure - Perce of GDP
## #   2005-2013` <dbl>, `Gross domestic product GDP 2013` <dbl>, `Gross
## #   domestic product GDP percapta` <dbl>, `Gross fixed capital formation
## #   of GDP 2005-2013` <dbl>, `Gross national income GNI per capita - 2011
## #   Dollars` <dbl>, `Homeless people due to natural disaster 2005 2014 per
## #   million people` <dbl>, `Homicide rate per 100k people
## #   2008-2012` <dbl>, `Infant Mortality 2013 per thousands` <dbl>,
## #   `International inbound tourists thausands 2013` <dbl>, `International
## #   student mobility of total tetiary enrolvemnt 2013` <dbl>, `Internet
## #   users percentage of population 2014` <dbl>, `Intimate or nonintimate
## #   partner violence ever experienced 2001-2011` <dbl>, `Life expectancy
## #   at birth- years` <dbl>, `MaleSuicide Rate 100k people` <dbl>,
## #   `Maternal mortality ratio deaths per 100 live births 2013` <dbl>,
## #   `Mean years of schooling - Years` <dbl>, `Mobile phone subscriptions
## #   per 100 people 2014` <dbl>, `Natural resource depletion` <dbl>, `Net
## #   migration rate per 1k people 2010-2015` <dbl>, `Physicians per 10k
## #   people` <dbl>, `Population affected by natural desasters average
## #   annual per million people 2005-2014` <dbl>, `Population living on
## #   degraded land Percentage 2010` <dbl>, `Population with at least some
## #   secondary education percent 2005-2013` <dbl>, `Pre-primary
## #   2008-2014` <dbl>, `Primary-2008-2014` <dbl>, `Primary school dropout
## #   rate 2008-2014` <dbl>, `Prison population per 100k people` <dbl>,
## #   `Private capital flows percentage GDP 2013` <dbl>, `Public expenditure
## #   on education Percentange GDP` <dbl>, `Public health expenditure
## #   percentage of GDP 2013` <dbl>, `Pupil-teacher ratio primary school
## #   pupils per teacher 2008-2014` <dbl>, `Refugees by country of
## #   origin` <dbl>, `Remittances inflows percentual GDP 2013` <dbl>,
## #   `Renewable sources percentage of total 2012` <dbl>, `Research and
## #   development expenditure 2005-2012` <dbl>, `Secondary 2008-2014` <dbl>,
## #   `Share of seats in parliament percentage held by womand 2014` <dbl>,
## #   `Stock of immigrants percentage of population 2013` <dbl>, `Taxes on
## #   income profit and capital gain 205 2013` <dbl>, `Tertiary
## #   -2008-2014` <dbl>, `Total tax revenue of GDP 2005-2013` <dbl>,
## #   `Tuberculosis rate per thousands 2012` <dbl>, `Under-five Mortality
## #   2013 thousands` <dbl>

Creating the Plot:

Let’s now create the plot:

p <- plot_ly(x =Kaggle$`Gross domestic product GDP percapta` , y = Kaggle$`Consumer price index 2013`, z = Kaggle$`Foreign direct investment net inflows percentage GDP 2013`, color = Kaggle$`Human Development Index HDI-2014`, colors = heat_hcl(12, alpha = 0.9))

layout(p, scene = list(xaxis = list(title = 'GDP percapta', color = 'royalblue4'), yaxis = list(title = 'Consumer Price Index 13', color = 'royalblue4'), zaxis = list(title = 'Foreign investment inflows', color = 'royalblue4')))
## No trace type specified:
##   Based on info supplied, a 'scatter3d' trace seems appropriate.
##   Read more about this trace type -> https://plot.ly/r/reference/#scatter3d
## No scatter3d mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode