summaryrefslogtreecommitdiff
path: root/images/twomoons.R
diff options
context:
space:
mode:
authorVivien Kraus <vivien@planete-kraus.eu>2021-04-07 12:05:36 +0200
committerVivien Kraus <vivien@planete-kraus.eu>2021-06-15 13:34:18 +0200
commitbb1ae75c56d34a65662d7b285333c595c0ddae7f (patch)
treee8baf732ce062603f0982ebc093fbd5451c45e65 /images/twomoons.R
Nouvelle version du manuscrit avec HTML
Diffstat (limited to 'images/twomoons.R')
-rwxr-xr-ximages/twomoons.R50
1 files changed, 50 insertions, 0 deletions
diff --git a/images/twomoons.R b/images/twomoons.R
new file mode 100755
index 0000000..c825abd
--- /dev/null
+++ b/images/twomoons.R
@@ -0,0 +1,50 @@
+#!/usr/bin/env Rscript
+t <- seq (0, 1, length.out = 101)
+labeled <- c (rep (0, 100), 1)
+upper_x <- cos (t * pi) + 0.5
+upper_y <- sin (t * pi)
+lower_x <- -upper_x
+lower_y <- -upper_y
+
+`%>%` <- magrittr::`%>%`
+
+data <- (tibble::tibble (x = upper_x, y = upper_y,
+ label = c (rep ("unlabeled", 100), "+"),
+ `semi-supervised solution` = "+")
+ %>% rbind (tibble::tibble (x = lower_x, y = lower_y,
+ label = c (rep ("unlabeled", 100), "-"),
+ `semi-supervised solution` = "-"))
+ %>% dplyr::mutate (noise_x = 0.1 * rnorm (dplyr::n ()),
+ noise_y = 0.1 * rnorm (dplyr::n ()))
+ %>% dplyr::mutate (x = x + noise_x, y = y + noise_y)
+ %>% dplyr::mutate (`naive solution` = ifelse (x <= 0, "+", "-")))
+
+scales <- function (plot) {
+ (plot
+ + ggplot2::scale_size_manual (values = c ("unlabeled" = 1, "+" = 3, "-" = 3))
+ + ggplot2::scale_shape_manual (values = c ("+" = 16, "-" = 17, "unlabeled" = 3))
+ + ggplot2::scale_color_manual (values = c ("+" = "#E69F00", "-" = "#56B4E9", "unlabeled" = "#009E73"))
+ + ggplot2::theme_void ()
+ + ggplot2::theme(legend.position="none")
+ + ggplot2::coord_fixed ())
+}
+
+question <- ((data
+ %>% ggplot2::ggplot (ggplot2::aes (x = x, y = y, shape = label, color = label, size = label))
+ + ggplot2::geom_point ())
+ %>% scales ())
+
+naive_answer <- ((data
+ %>% ggplot2::ggplot (ggplot2::aes (x = x, y = y, shape = `naive solution`, color = `naive solution`))
+ + ggplot2::geom_point ()
+ + ggplot2::geom_vline (xintercept = 0))
+ %>% scales ())
+
+semi_supervised_answer <- ((data
+ %>% ggplot2::ggplot (ggplot2::aes (x = x, y = y, shape = `semi-supervised solution`, color = `semi-supervised solution`))
+ + ggplot2::geom_point ())
+ %>% scales ())
+
+plot <- gridExtra::arrangeGrob (question, gridExtra::arrangeGrob (naive_answer, semi_supervised_answer, ncol = 2), nrow = 2)
+filename <- Sys.getenv ("OUTPUT")
+ggplot2::ggsave (filename, plot, device = "svg", width = 3.5, height = 3.5)