Skip to content

Commit 3f8ca6c

Browse files
points overtop lines in the cluster distance diagrams
1 parent 67baa3e commit 3f8ca6c

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

source/clustering.Rmd

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,7 @@ These distances are denoted by lines in Figure \@ref(fig:10-toy-example-clus1-di
359359
(ref:10-toy-example-clus1-dists) Cluster 1 from the `penguins_standardized` data set example. Observations are in blue, with the cluster center highlighted in red. The distances from the observations to the cluster center are represented as black lines.
360360

361361
```{r 10-toy-example-clus1-dists, echo = FALSE, warning = FALSE, fig.height = 3.25, fig.width = 3.5, fig.align = "center", fig.cap = "(ref:10-toy-example-clus1-dists)"}
362-
base <- ggplot(clus1) +
363-
geom_point(aes(y = bill_length_standardized,
364-
x = flipper_length_standardized),
365-
col = "dodgerblue3") +
366-
labs(x = "Flipper Length (standardized)", y = "Bill Length (standardized)") +
367-
theme(legend.position = "none")
362+
base <- ggplot(clus1)
368363
369364
mn <- clus1 |>
370365
summarize(flipper_length_standardized = mean(flipper_length_standardized),
@@ -382,6 +377,14 @@ base <- base +
382377
x = mean(flipper_length_standardized)),
383378
color = "#F8766D",
384379
size = 5)
380+
381+
base <- base +
382+
geom_point(aes(y = bill_length_standardized,
383+
x = flipper_length_standardized),
384+
col = "dodgerblue3") +
385+
labs(x = "Flipper Length (standardized)", y = "Bill Length (standardized)") +
386+
theme(legend.position = "none")
387+
385388
base
386389
```
387390

@@ -399,16 +402,8 @@ Figure \@ref(fig:10-toy-example-all-clus-dists).
399402
(ref:10-toy-example-all-clus-dists) All clusters from the `penguins_standardized` data set example. Observations are in orange, blue, and yellow with the cluster center highlighted in red. The distances from the observations to each of the respective cluster centers are represented as black lines.
400403

401404
```{r 10-toy-example-all-clus-dists, echo = FALSE, warning = FALSE, fig.height = 3.25, fig.width = 4.25, fig.align = "center", fig.cap = "(ref:10-toy-example-all-clus-dists)"}
402-
all_clusters_base <- penguins_clustered |>
403-
ggplot(aes(y = bill_length_standardized,
404-
x = flipper_length_standardized,
405-
color = cluster)) +
406-
geom_point() +
407-
xlab("Flipper Length (standardized)") +
408-
ylab("Bill Length (standardized)") +
409-
scale_color_manual(values= c("darkorange3",
410-
"dodgerblue3",
411-
"goldenrod1"))
405+
all_clusters_base <- ggplot(penguins_clustered)
406+
412407
cluster_centers <- tibble(x = c(0, 0, 0),
413408
y = c(0, 0, 0))
414409
@@ -435,6 +430,16 @@ for (cluster_number in seq_along(1:3)) {
435430
cluster_centers[cluster_number, 2] <- mean(clus$bill_length_standardized)
436431
}
437432
433+
all_clusters_base <- all_clusters_base +
434+
geom_point(aes(y = bill_length_standardized,
435+
x = flipper_length_standardized,
436+
color = cluster)) +
437+
xlab("Flipper Length (standardized)") +
438+
ylab("Bill Length (standardized)") +
439+
scale_color_manual(values= c("darkorange3",
440+
"dodgerblue3",
441+
"goldenrod1"))
442+
438443
all_clusters_base <- all_clusters_base +
439444
geom_point(aes(y = cluster_centers$y[1],
440445
x = cluster_centers$x[1]),

0 commit comments

Comments
 (0)