diff --git a/modules/06-dataviz/R_viz.ipynb b/modules/06-dataviz/R_viz.ipynb index 66190b0..01a035e 100644 --- a/modules/06-dataviz/R_viz.ipynb +++ b/modules/06-dataviz/R_viz.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 17, + "execution_count": 66, "id": "earned-theology", "metadata": { "vscode": { @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 67, "id": "executive-hearing", "metadata": { "vscode": { @@ -121,7 +121,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 68, "id": "protecting-associate", "metadata": { "vscode": { @@ -153,7 +153,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 69, "id": "resistant-marketplace", "metadata": { "vscode": { @@ -195,7 +195,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 70, "id": "postal-confidence", "metadata": { "vscode": { @@ -238,7 +238,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 71, "id": "dangerous-defeat", "metadata": { "vscode": { @@ -271,7 +271,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 72, "id": "immediate-infrared", "metadata": { "vscode": { @@ -343,7 +343,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 73, "id": "worst-turner", "metadata": { "vscode": { @@ -384,7 +384,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 74, "id": "frank-holmes", "metadata": { "vscode": { @@ -433,7 +433,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 75, "id": "developed-carnival", "metadata": { "vscode": { @@ -487,7 +487,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 76, "id": "removed-stroke", "metadata": { "vscode": { @@ -547,7 +547,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 77, "id": "continued-elite", "metadata": { "vscode": { @@ -760,7 +760,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 78, "id": "accomplished-pension", "metadata": { "vscode": { @@ -786,7 +786,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 79, "id": "billion-victorian", "metadata": { "vscode": { @@ -1000,52 +1000,8 @@ }, { "cell_type": "code", - "execution_count": 31, - "id": "attractive-hygiene", - "metadata": { - "vscode": { - "languageId": "r" - } - }, - "outputs": [], - "source": [ - "# https://stackoverflow.com/questions/35717353/split-violin-plot-with-ggplot2\n", - "GeomSplitViolin <- ggproto(\"GeomSplitViolin\", GeomViolin, \n", - " draw_group = function(self, data, ..., draw_quantiles = NULL) {\n", - " data <- transform(data, xminv = x - violinwidth * (x - xmin), xmaxv = x + violinwidth * (xmax - x))\n", - " grp <- data[1, \"group\"]\n", - " newdata <- plyr::arrange(transform(data, x = if (grp %% 2 == 1) xminv else xmaxv), if (grp %% 2 == 1) y else -y)\n", - " newdata <- rbind(newdata[1, ], newdata, newdata[nrow(newdata), ], newdata[1, ])\n", - " newdata[c(1, nrow(newdata) - 1, nrow(newdata)), \"x\"] <- round(newdata[1, \"x\"])\n", - "\n", - " if (length(draw_quantiles) > 0 & !scales::zero_range(range(data$y))) {\n", - " stopifnot(all(draw_quantiles >= 0), all(draw_quantiles <=\n", - " 1))\n", - " quantiles <- ggplot2:::create_quantile_segment_frame(data, draw_quantiles)\n", - " aesthetics <- data[rep(1, nrow(quantiles)), setdiff(names(data), c(\"x\", \"y\")), drop = FALSE]\n", - " aesthetics$alpha <- rep(1, nrow(quantiles))\n", - " both <- cbind(quantiles, aesthetics)\n", - " quantile_grob <- GeomPath$draw_panel(both, ...)\n", - " ggplot2:::ggname(\"geom_split_violin\", grid::grobTree(GeomPolygon$draw_panel(newdata, ...), quantile_grob))\n", - " }\n", - " else {\n", - " ggplot2:::ggname(\"geom_split_violin\", GeomPolygon$draw_panel(newdata, ...))\n", - " }\n", - "})\n", - "\n", - "geom_split_violin <- function(mapping = NULL, data = NULL, stat = \"ydensity\", position = \"identity\", ..., \n", - " draw_quantiles = NULL, trim = TRUE, scale = \"area\", na.rm = FALSE, \n", - " show.legend = NA, inherit.aes = TRUE) {\n", - " layer(data = data, mapping = mapping, stat = stat, geom = GeomSplitViolin, \n", - " position = position, show.legend = show.legend, inherit.aes = inherit.aes, \n", - " params = list(trim = trim, scale = scale, draw_quantiles = draw_quantiles, na.rm = na.rm, ...))\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "id": "eleven-legend", + "execution_count": 80, + "id": "607b857b", "metadata": { "vscode": { "languageId": "r"