# Attach packages
library(rearrr)
library(dplyr)
has_ggplot <- require(ggplot2) # Attach if installed
# Set seed
set.seed(10)
# Generate clusters
generate_clusters(num_rows = 20, num_cols = 3, num_clusters = 3, compactness = 1.6)
generate_clusters(num_rows = 20, num_cols = 5, num_clusters = 6, compactness = 2.5)
# Generate clusters and plot them
# Tip: Call this multiple times
# to see the behavior of `generate_clusters()`
if (has_ggplot){
generate_clusters(
num_rows = 50, num_cols = 2,
num_clusters = 5, compactness = 1.6
) %>%
ggplot(
aes(x = D1, y = D2, color = .cluster)
) +
geom_point() +
theme_minimal() +
labs(x = "D1", y = "D2", color = "Cluster")
}
#
# Plot clusters in 3d view
#
# Generate clusters
clusters <- generate_clusters(
num_rows = 50, num_cols = 3,
num_clusters = 5, compactness = 1.6
)
if (FALSE) {
# Plot 3d with plotly
plotly::plot_ly(
x = clusters$D1,
y = clusters$D2,
z = clusters$D3,
type = "scatter3d",
mode = "markers",
color = clusters$.cluster
)
}
Run the code above in your browser using DataLab