CLB
2026-05-21
First, the rubric requires a date, so we’ll ask R for that:
## [1] "2026-05-21"
And then load the needed libraries:
Next, we’ll see how many observations are in the
diamonds data set:
## [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)
)
)Kindly review the notes regarding the nature of the scales on the next slide.