Skip to content

Commit

Permalink
Rviz_update2
Browse files Browse the repository at this point in the history
  • Loading branch information
mollysacks committed Sep 13, 2024
1 parent d14487b commit 95ce480
Showing 1 changed file with 16 additions and 60 deletions.
76 changes: 16 additions & 60 deletions modules/06-dataviz/R_viz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 66,
"id": "earned-theology",
"metadata": {
"vscode": {
Expand All @@ -26,7 +26,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 67,
"id": "executive-hearing",
"metadata": {
"vscode": {
Expand Down Expand Up @@ -121,7 +121,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 68,
"id": "protecting-associate",
"metadata": {
"vscode": {
Expand Down Expand Up @@ -153,7 +153,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 69,
"id": "resistant-marketplace",
"metadata": {
"vscode": {
Expand Down Expand Up @@ -195,7 +195,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 70,
"id": "postal-confidence",
"metadata": {
"vscode": {
Expand Down Expand Up @@ -238,7 +238,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 71,
"id": "dangerous-defeat",
"metadata": {
"vscode": {
Expand Down Expand Up @@ -271,7 +271,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 72,
"id": "immediate-infrared",
"metadata": {
"vscode": {
Expand Down Expand Up @@ -343,7 +343,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 73,
"id": "worst-turner",
"metadata": {
"vscode": {
Expand Down Expand Up @@ -384,7 +384,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 74,
"id": "frank-holmes",
"metadata": {
"vscode": {
Expand Down Expand Up @@ -433,7 +433,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 75,
"id": "developed-carnival",
"metadata": {
"vscode": {
Expand Down Expand Up @@ -487,7 +487,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 76,
"id": "removed-stroke",
"metadata": {
"vscode": {
Expand Down Expand Up @@ -547,7 +547,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 77,
"id": "continued-elite",
"metadata": {
"vscode": {
Expand Down Expand Up @@ -760,7 +760,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 78,
"id": "accomplished-pension",
"metadata": {
"vscode": {
Expand All @@ -786,7 +786,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 79,
"id": "billion-victorian",
"metadata": {
"vscode": {
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 95ce480

Please sign in to comment.