Plotly/Rmarkdown Presentation

Developing Data Products mod. 04 assignment

CLB

2026-05-21

Diamond prices

As influenced by the GIA’s “Four Cs”: Color, Cut, Clarity, and Carat (weight).

First, the rubric requires a date, so we’ll ask R for that:

Sys.Date()
## [1] "2026-05-21"

And then load the needed libraries:

suppressMessages(library(plotly))
suppressMessages(library(tidyverse))

Next, we’ll see how many observations are in the diamonds data set:

dim(diamonds)
## [1] 53940    10

That’s a lot of observations, and that many points will muddy the plot. So we’ll look at a random subset consisting of 5% of the data set:

set.seed(8675309)
dsample <- slice_sample(diamonds, n = dim(diamonds)[1] * 0.05)
print.default(paste('Sample observations:', dim(dsample)[1]))
## [1] "Sample observations: 2697"

And generate the plot:

d_plot <- plot_ly(data = dsample, type = 'scatter3d', 
                  mode = 'markers',
                  x = ~carat, y = ~clarity, z = ~price, 
                  color = ~cut,
                  opacity = 0.75, 
                  marker = list(size = 3), 
                  hovertemplate = paste('Price: $', dsample$price, 
                                        '<br>Weight: ', dsample$carat,
                                        '<br>Clarity: ', dsample$clarity,
                                        '<br>Color: ',dsample$color,
                                        sep = ''),
                  legendgrouptitle = list(text = 'Cut', 
                                          font = list(size = 20)
                                          )
)

3D scatter plot of dsample

Kindly review the notes regarding the nature of the scales on the next slide.

The Scales of Diamond Grading:

The industry-standard grading system is that of the Gemological Institute of America.