Last active
April 21, 2021 09:58
-
-
Save vankesteren/e7070e491a410a6cd4d1fb6dceeb74aa to your computer and use it in GitHub Desktop.
Revisions
-
vankesteren revised this gist
Apr 21, 2021 . 1 changed file with 8 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,14 +13,14 @@ wine <- read_delim("https://archive.ics.uci.edu/ml/machine-learning-databases/wi wine_long <- wine %>% mutate(Cultivar = as_factor(Cultivar)) %>% pivot_longer(-Cultivar) wine_long %>% filter(name != "Total phenols") %>% ggplot(aes(x = value, fill = Cultivar, colour = Cultivar)) + geom_density(alpha = 0.8, colour = "black") + geom_rug() + facet_wrap(~name, scales = 'free') + theme_fira() + scale_fill_fira() + scale_colour_fira() + @@ -32,12 +32,14 @@ wine_long %>% ggsave("wine_plot.pdf", device = cairo_pdf, width = 12, height = 8) pca <- prcomp(wine[,-1], scale. = TRUE) pc12 <- pca$x[,1:2] as_tibble(pc12) %>% set_names("x", "y") %>% mutate(Cultivar = as_factor(wine$Cultivar)) %>% ggplot(aes(x = x, y = y, colour = Cultivar, fill = Cultivar)) + geom_polygon(stat = "density_2d", alpha = 0.1, colour = NA, contour = TRUE) + geom_point() + coord_fixed() + theme_fira() + -
vankesteren revised this gist
Nov 29, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,7 +33,7 @@ wine_long %>% ggsave("wine_plot.pdf", device = cairo_pdf, width = 12, height = 8) pca <- princomp(wine[,-1], cor = TRUE)$scores[,1:2] as_tibble(pca) %>% set_names("x", "y") %>% mutate(Cultivar = as_factor(wine$Cultivar)) %>% ggplot(aes(x = x, y = y, colour = Cultivar, fill = Cultivar)) + -
vankesteren created this gist
Nov 28, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ # script that outputs a graph library(tidyverse) library(firatheme) wine <- read_delim("https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data", delim = ",", col_names = c( "Cultivar", "Alcohol", "Malic acid", "Ash", "Alcalinity of ash", "Magnesium", "Total phenols", "Flavanoids", "Nonflavanoid phenols", "Proanthocyanins", "Color intensity", "Hue", "OD280/OD315", "Proline" ) ) wine_long <- wine %>% mutate(Cultivar = as_factor(Cultivar)) %>% gather(key = "variable", value = "value", -Cultivar) wine_long %>% filter(variable != "Total phenols") %>% ggplot(aes(x = value, fill = Cultivar, colour = Cultivar)) + geom_density(alpha = 0.8, colour = "black") + geom_rug() + facet_wrap(~variable, scales = 'free') + theme_fira() + scale_fill_fira() + scale_colour_fira() + labs( x = "", y = "", title = "Chemical properties of three different wine cultivars" ) ggsave("wine_plot.pdf", device = cairo_pdf, width = 12, height = 8) pca <- princomp(wine[,-1], cor = TRUE)$scores[,1:2] as_tibble(umap) %>% set_names("x", "y") %>% mutate(Cultivar = as_factor(wine$Cultivar)) %>% ggplot(aes(x = x, y = y, colour = Cultivar, fill = Cultivar)) + geom_polygon(stat = "density_2d", alpha = 0.1, colour = NA) + geom_point() + coord_fixed() + theme_fira() + scale_colour_fira() + scale_fill_fira() + xlim(-7, 7) + labs(x = "First principal component", y = "Second principal component") ggsave("pca_plot.pdf", device = cairo_pdf, width = 12, height = 6)