With the preprocessing finished, let’s first visualize the three dimensions for each flower.
A colorscale is used to show the relative price of each flower; lighter colors are higher priced.
We’ll use the Plotly library to achieve this.
Code:
suppressPackageStartupMessages(library(plotly))
xax = list(
title = "Petal Width",
titlefont = list(family = "Noto Sans")
)
yax = list(
title = "Petal Length",
titlefont = list(family = "Noto Sans")
)
zax = list(
title = "Sepal Width",
titlefont = list(family = "Noto Sans")
)
# Referenced plotly.com's documentation on 3d scatter plots
fig = plot_ly(df, x = ~PW, y = ~PL, z = ~SW,
type = "scatter3d",
mode = "markers",
marker = list(color = ~FP,
colorscale = "Viridis",
showscale = TRUE)) %>%
add_markers() %>%
layout(scene = list(xaxis = xax,
yaxis = yax,
zaxis = zax),
annotations = list(
x = 1,
y = 1,
text = "Relative Flower Price",
xref = "paper",
yref = "paper",
showarrow = FALSE),
showlegend = FALSE)
fig
[Backup Image of 3D Plotly]
The 3D plot shows a more comprehensive overview of the flower dataset, especially with the range of flower prices going from below ten dollars to over 50 dollars. That is an especially significant range.
However, with the major spread of flower prices, it is still difficult to determine how much profit a batch of 150 flowers will yield.
As such, we’ll use Monte Carlo simulation to get a probable range of profit margins.