Skip to content

Commit 750b131

Browse files
committed
Added centering to figures where it was missing
1 parent bdc7eb5 commit 750b131

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

clustering.Rmd

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ penguin_data
164164
Next, we can create a scatter plot using this data set
165165
to see if we can detect subtypes or groups in our data set.
166166

167-
```{r 10-toy-example-plot, warning = FALSE, fig.height = 4, fig.width = 4.35, fig.cap = "Scatter plot of standardized bill length versus standardized flipper length."}
167+
```{r 10-toy-example-plot, warning = FALSE, fig.height = 4, fig.width = 4.35, fig.align = "center", fig.cap = "Scatter plot of standardized bill length versus standardized flipper length."}
168168
ggplot(data, aes(x = flipper_length_standardized,
169169
y = bill_length_standardized)) +
170170
geom_point() +
@@ -198,7 +198,7 @@ This procedure will separate the data into groups;
198198
Figure \@ref(fig:10-toy-example-clustering) shows these groups
199199
denoted by colored scatter points.
200200

201-
```{r 10-toy-example-clustering, echo = FALSE, warning = FALSE, fig.height = 4, fig.width = 5, fig.cap = "Scatter plot of standardized bill length versus standardized flipper length with colored groups."}
201+
```{r 10-toy-example-clustering, echo = FALSE, warning = FALSE, fig.height = 4, fig.width = 5, fig.align = "center", fig.cap = "Scatter plot of standardized bill length versus standardized flipper length with colored groups."}
202202
ggplot(data, aes(y = bill_length_standardized,
203203
x = flipper_length_standardized, color = cluster)) +
204204
geom_point() +
@@ -256,7 +256,7 @@ in Figure \@ref(fig:10-toy-example-clus1-center).
256256

257257
(ref:10-toy-example-clus1-center) Cluster 1 from the `penguin_data` data set example. Observations are in blue, with the cluster center highlighted in red.
258258

259-
```{r 10-toy-example-clus1-center, echo = FALSE, warning = FALSE, fig.height = 4, fig.width = 4.35, fig.cap = "(ref:10-toy-example-clus1-center)"}
259+
```{r 10-toy-example-clus1-center, echo = FALSE, warning = FALSE, fig.height = 4, fig.width = 4.35, fig.align = "center", fig.cap = "(ref:10-toy-example-clus1-center)"}
260260
base <- ggplot(data, aes(x = flipper_length_standardized, y = bill_length_standardized)) +
261261
geom_point() +
262262
xlab("Flipper Length (standardized)") +
@@ -303,7 +303,7 @@ These distances are denoted by lines in Figure \@ref(fig:10-toy-example-clus1-di
303303

304304
(ref:10-toy-example-clus1-dists) Cluster 1 from the `penguin_data` 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.
305305

306-
```{r 10-toy-example-clus1-dists, echo = FALSE, warning = FALSE, fig.height = 4, fig.width = 4.35, fig.cap = "(ref:10-toy-example-clus1-dists)"}
306+
```{r 10-toy-example-clus1-dists, echo = FALSE, warning = FALSE, fig.height = 4, fig.width = 4.35, fig.align = "center", fig.cap = "(ref:10-toy-example-clus1-dists)"}
307307
base <- ggplot(clus1) +
308308
geom_point(aes(y = bill_length_standardized,
309309
x = flipper_length_standardized),
@@ -342,7 +342,7 @@ Figure \@ref(fig:10-toy-example-all-clus-dists).
342342

343343
(ref:10-toy-example-all-clus-dists) All clusters from the `penguin_data` 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.
344344

345-
```{r 10-toy-example-all-clus-dists, echo = FALSE, warning = FALSE, fig.height = 4, fig.width = 5, fig.cap = "(ref:10-toy-example-all-clus-dists)"}
345+
```{r 10-toy-example-all-clus-dists, echo = FALSE, warning = FALSE, fig.height = 4, fig.width = 5, fig.align = "center", fig.cap = "(ref:10-toy-example-all-clus-dists)"}
346346
347347
348348
all_clusters_base <- data |>
@@ -408,7 +408,7 @@ and randomly assigning a roughly equal number of observations
408408
to each of the K clusters.
409409
An example random initialization is shown in Figure \@ref(fig:10-toy-kmeans-init).
410410

411-
```{r 10-toy-kmeans-init, echo = FALSE, message = FALSE, warning = FALSE, fig.height = 4, fig.width = 4.35, fig.cap = "Random initialization of labels."}
411+
```{r 10-toy-kmeans-init, echo = FALSE, message = FALSE, warning = FALSE, fig.height = 4, fig.width = 4.35, fig.align = "center", fig.cap = "Random initialization of labels."}
412412
set.seed(14)
413413
penguin_data["label"] <- factor(sample(1:3, nrow(penguin_data), replace = TRUE))
414414
@@ -439,7 +439,7 @@ and the right column depicts the reassignment of data to clusters.
439439

440440
(ref:10-toy-kmeans-iter) First four iterations of K-means clustering on the `penguin_data` example data set. Each row corresponds to an iteration, where the left column depicts the center update, and the right column depicts the reassignment of data to clusters. Cluster centers are indicated by larger points that are outlined in black.
441441

442-
```{r 10-toy-kmeans-iter, echo = FALSE, warning = FALSE, fig.height = 16, fig.width = 8, fig.cap = "(ref:10-toy-kmeans-iter)"}
442+
```{r 10-toy-kmeans-iter, echo = FALSE, warning = FALSE, fig.height = 16, fig.width = 8, fig.align = "center", fig.cap = "(ref:10-toy-kmeans-iter)"}
443443
list_plot_cntrs <- vector(mode = "list", length = 4)
444444
list_plot_lbls <- vector(mode = "list", length = 4)
445445
@@ -546,7 +546,7 @@ These, however, are beyond the scope of this book.
546546
Unlike the classification and regression models we studied in previous chapters, K-means \index{K-means!restart,nstart} can get "stuck" in a bad solution.
547547
For example, Figure \@ref(fig:10-toy-kmeans-bad-init) illustrates an unlucky random initialization by K-means.
548548

549-
```{r 10-toy-kmeans-bad-init, echo = FALSE, warning = FALSE, message = FALSE, fig.height = 4, fig.width = 4.35, fig.cap = "Random initialization of labels."}
549+
```{r 10-toy-kmeans-bad-init, echo = FALSE, warning = FALSE, message = FALSE, fig.height = 4, fig.width = 4.35, fig.align = "center", fig.cap = "Random initialization of labels."}
550550
penguin_data <- penguin_data |>
551551
mutate(label = as_factor(c(3L, 3L, 1L, 1L, 2L, 1L, 2L, 1L, 1L,
552552
1L, 3L, 1L, 2L, 2L, 2L, 3L, 3L, 3L)))
@@ -567,7 +567,7 @@ Figure \@ref(fig:10-toy-kmeans-bad-iter) shows what the iterations of K-means wo
567567

568568
(ref:10-toy-kmeans-bad-iter) First five iterations of K-means clustering on the `penguin_data` example data set with a poor random initialization. Each row corresponds to an iteration, where the left column depicts the center update, and the right column depicts the reassignment of data to clusters. Cluster centers are indicated by larger points that are outlined in black.
569569

570-
```{r 10-toy-kmeans-bad-iter, echo = FALSE, warning = FALSE, fig.height = 20, fig.width = 8, fig.cap = "(ref:10-toy-kmeans-bad-iter)"}
570+
```{r 10-toy-kmeans-bad-iter, echo = FALSE, warning = FALSE, fig.height = 20, fig.width = 8, fig.align = "center", fig.cap = "(ref:10-toy-kmeans-bad-iter)"}
571571
list_plot_cntrs <- vector(mode = "list", length = 5)
572572
list_plot_lbls <- vector(mode = "list", length = 5)
573573
@@ -959,7 +959,7 @@ but there is a trade-off that doing many clusterings
959959
could take a long time.
960960
So this is something that needs to be balanced.
961961

962-
```{r 10-choose-k-nstart, fig.height = 4, fig.width = 4.35, message= F, warning = F, fig.cap = "A plot showing the total WSSD versus the number of clusters when K-means is run with 10 restarts."}
962+
```{r 10-choose-k-nstart, fig.height = 4, fig.width = 4.35, message= FALSE, warning = FALSE, fig.align = "center", fig.cap = "A plot showing the total WSSD versus the number of clusters when K-means is run with 10 restarts."}
963963
penguin_clust_ks <- tibble(k = 1:9) |>
964964
rowwise() |>
965965
mutate(penguin_clusts = list(kmeans(standardized_data, nstart = 10, k)),

0 commit comments

Comments
 (0)