R Markdown Presentation and Plotly

Adrian R Angkawijaya

5/19/2018

Data

The project involves the visualization of diamonds prices according to their weight. The visualization is done with plotly and the dateset is the diamonds dataset from the ggplot package in R.

The data is sampled to 1000 rows to make it easier to read the visualization.

The dataset

library(ggplot2)
diamonds <- diamonds[sample(nrow(diamonds), 1000),]
head(diamonds)
## # A tibble: 6 x 10
##   carat       cut color clarity depth table price     x     y     z
##   <dbl>     <ord> <ord>   <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
## 1  0.40     Ideal     E    VVS2  61.7    55  1238  4.76  4.74  2.93
## 2  0.41     Ideal     D     SI1  62.2    57  1015  4.76  4.70  2.94
## 3  2.25   Premium     I     SI2  61.9    59 11114  8.42  8.35  5.19
## 4  1.02 Very Good     F      IF  62.5    58 10967  6.39  6.54  4.04
## 5  0.34   Premium     D     SI1  60.2    60   803  4.54  4.50  2.72
## 6  0.56 Very Good     F     VS1  61.2    58  1929  5.32  5.33  3.26

The plot

library(plotly)
## 
## 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

The plot

plot_ly(x = diamonds$carat, y = diamonds$price, color = diamonds$carat)
## No trace type specified:
##   Based on info supplied, a 'scatter' trace seems appropriate.
##   Read more about this trace type -> https://plot.ly/r/reference/#scatter
## No scatter mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode

Thank you!