Skip to content

Commit 4cc574a

Browse files
committed
removing axes labels in between plots, making a common label
1 parent 06726b1 commit 4cc574a

File tree

2 files changed

+118
-8
lines changed

2 files changed

+118
-8
lines changed

classification2.Rmd

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ a balance between the two. You can see these two effects in Figure
848848
\@ref(fig:06-decision-grid-K), which shows how the classifier changes as
849849
we set the number of neighbors $K$ to 1, 7, 20, and 300.
850850

851-
```{r 06-decision-grid-K, echo = FALSE, message = FALSE, fig.height = 7, fig.width = 10, fig.cap = "Effect of K in overfitting and underfitting."}
851+
```{r 06-decision-grid-K, echo = FALSE, message = FALSE, fig.height = 10, fig.width = 10, fig.cap = "Effect of K in overfitting and underfitting."}
852852
ks <- c(1, 7, 20, 300)
853853
plots <- list()
854854
@@ -895,7 +895,10 @@ for (i in 1:length(ks)) {
895895
scale_color_manual(labels = c("Malignant", "Benign"),
896896
values = c("orange2", "steelblue2"))
897897
}
898-
grid.arrange(grobs = plots)
898+
p_no_legend <- lapply(plots, function(x) x + theme(legend.position = "none"))
899+
legend <- get_legend(plots[[1]] + theme(legend.position = "bottom"))
900+
p_grid <- plot_grid(plotlist = p_no_legend, ncol = 2)
901+
plot_grid(p_grid, legend, ncol = 1, rel_heights = c(1, 0.2))
899902
```
900903

901904
## Summary

clustering.Rmd

Lines changed: 113 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ library(RColorBrewer)
66
library(gridExtra)
77
library(cowplot)
88
library(broom)
9+
library(egg) # ggarrange
10+
911
1012
#center breaks latex here
1113
knitr::opts_chunk$set(warning = FALSE, fig.align = "default")
@@ -516,9 +518,52 @@ iter_plot_list <- c(list_plot_cntrs[1], list_plot_lbls[1],
516518
list_plot_cntrs[3], list_plot_lbls[3],
517519
list_plot_cntrs[4], list_plot_lbls[4])
518520
519-
plot_grid(plotlist = iter_plot_list,
520-
nrow = 2,
521-
rel_heights = c(1.15, 1))
521+
ggarrange(iter_plot_list[[1]] +
522+
theme(axis.text.x = element_blank(),
523+
axis.ticks.x = element_blank(),
524+
axis.title.x = element_blank(),
525+
plot.margin = margin(r = 2, b = 2)),
526+
iter_plot_list[[2]] +
527+
theme(axis.text.y = element_blank(),
528+
axis.ticks.y = element_blank(),
529+
axis.title.y = element_blank(),
530+
axis.text.x = element_blank(),
531+
axis.ticks.x = element_blank(),
532+
axis.title.x = element_blank(),
533+
plot.margin = margin(r = 2, l = 2, b = 2) ),
534+
iter_plot_list[[3]] +
535+
theme(axis.text.y = element_blank(),
536+
axis.ticks.y = element_blank(),
537+
axis.title.y = element_blank(),
538+
axis.text.x = element_blank(),
539+
axis.ticks.x = element_blank(),
540+
axis.title.x = element_blank(),
541+
plot.margin = margin(r = 2, l = 2, b = 2) ),
542+
iter_plot_list[[4]] +
543+
theme(axis.text.y = element_blank(),
544+
axis.ticks.y = element_blank(),
545+
axis.title.y = element_blank(),
546+
axis.text.x = element_blank(),
547+
axis.ticks.x = element_blank(),
548+
axis.title.x = element_blank(),
549+
plot.margin = margin(l = 2, b = 2) ),
550+
iter_plot_list[[5]] +
551+
theme(plot.margin = margin(r = 2, t = 2)),
552+
iter_plot_list[[6]] +
553+
theme(axis.text.y = element_blank(),
554+
axis.ticks.y = element_blank(),
555+
axis.title.y = element_blank(),
556+
plot.margin = margin(r = 2, l = 2, t = 2) ),
557+
iter_plot_list[[7]] +
558+
theme(axis.text.y = element_blank(),
559+
axis.ticks.y = element_blank(),
560+
axis.title.y = element_blank(),
561+
plot.margin = margin(r = 2, l = 2, t = 2) ),
562+
iter_plot_list[[8]] + theme(axis.text.y = element_blank(),
563+
axis.ticks.y = element_blank(),
564+
axis.title.y = element_blank(),
565+
plot.margin = margin(l = 2, t = 2) ),
566+
nrow = 2)
522567
```
523568

524569
Note that at this point, we can terminate the algorithm since none of the assignments changed
@@ -644,9 +689,71 @@ iter_plot_list <- c(list_plot_cntrs[1], list_plot_lbls[1],
644689
list_plot_cntrs[4], list_plot_lbls[4],
645690
list_plot_cntrs[5], list_plot_lbls[5])
646691
647-
plot_grid(plotlist = iter_plot_list,
648-
ncol = 4,
649-
rel_heights = c(1.10, 1, 1))
692+
# plot_grid(plotlist = iter_plot_list,
693+
# ncol = 4,
694+
# rel_heights = c(1.10, 1, 1))
695+
696+
697+
698+
ggarrange(iter_plot_list[[1]] +
699+
theme(axis.text.x = element_blank(),
700+
axis.ticks.x = element_blank(),
701+
axis.title.x = element_blank(),
702+
plot.margin = margin(r = 2, b = 2)),
703+
iter_plot_list[[2]] +
704+
theme(axis.text.y = element_blank(),
705+
axis.ticks.y = element_blank(),
706+
axis.title.y = element_blank(),
707+
axis.text.x = element_blank(),
708+
axis.ticks.x = element_blank(),
709+
axis.title.x = element_blank(),
710+
plot.margin = margin(r = 2, l = 2, b = 2) ),
711+
iter_plot_list[[3]] +
712+
theme(axis.text.y = element_blank(),
713+
axis.ticks.y = element_blank(),
714+
axis.title.y = element_blank(),
715+
axis.text.x = element_blank(),
716+
axis.ticks.x = element_blank(),
717+
axis.title.x = element_blank(),
718+
plot.margin = margin(r = 2, l = 2, b = 2)),
719+
iter_plot_list[[4]] +
720+
theme(axis.text.y = element_blank(),
721+
axis.ticks.y = element_blank(),
722+
axis.title.y = element_blank(),
723+
axis.text.x = element_blank(),
724+
axis.ticks.x = element_blank(),
725+
axis.title.x = element_blank(),
726+
plot.margin = margin(l = 2, b = 2) ),
727+
iter_plot_list[[5]] +
728+
theme(axis.text.x = element_blank(),
729+
axis.ticks.x = element_blank(),
730+
axis.title.x = element_blank(),
731+
plot.margin = margin(r = 2, t = 2, b = 1)),
732+
iter_plot_list[[6]] +
733+
theme(axis.text.y = element_blank(),
734+
axis.ticks.y = element_blank(),
735+
axis.title.y = element_blank(),
736+
axis.text.x = element_blank(),
737+
axis.ticks.x = element_blank(),
738+
axis.title.x = element_blank(),
739+
plot.margin = margin(r = 2, l = 2, t = 2, b = 1) ),
740+
iter_plot_list[[7]] +
741+
theme(axis.text.y = element_blank(),
742+
axis.ticks.y = element_blank(),
743+
axis.title.y = element_blank(),
744+
plot.margin = margin(r = 2, l = 2, t = 2, b = 2) ),
745+
iter_plot_list[[8]] + theme(axis.text.y = element_blank(),
746+
axis.ticks.y = element_blank(),
747+
axis.title.y = element_blank(),
748+
plot.margin = margin(l = 2, t = 2, b = 2)),
749+
iter_plot_list[[9]] +
750+
theme(plot.margin = margin(r = 2)),
751+
iter_plot_list[[10]] +
752+
theme(axis.text.y = element_blank(),
753+
axis.ticks.y = element_blank(),
754+
axis.title.y = element_blank(),
755+
plot.margin = margin(l = 2) ),
756+
ncol = 4)
650757
```
651758

652759
This looks like a relatively bad clustering of the data, but K-means cannot improve it.

0 commit comments

Comments
 (0)