Created
October 26, 2017 08:52
-
-
Save flying-sheep/0f6079360071ca2f76da047ed93f40ac to your computer and use it in GitHub Desktop.
This file contains 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 characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"library(grid)\n", | |
"library(tidyverse)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 70, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<style>.knitr .inline {\n", | |
" background-color: #f7f7f7;\n", | |
" border:solid 1px #B0B0B0;\n", | |
"}\n", | |
".error {\n", | |
"\tfont-weight: bold;\n", | |
"\tcolor: #FF0000;\n", | |
"}\n", | |
".warning {\n", | |
"\tfont-weight: bold;\n", | |
"}\n", | |
".message {\n", | |
"\tfont-style: italic;\n", | |
"}\n", | |
".source, .output, .warning, .error, .message {\n", | |
"\tpadding: 0 1em;\n", | |
" border:solid 1px #F7F7F7;\n", | |
"}\n", | |
".source {\n", | |
" background-color: #f5f5f5;\n", | |
"}\n", | |
".rimage .left {\n", | |
" text-align: left;\n", | |
"}\n", | |
".rimage .right {\n", | |
" text-align: right;\n", | |
"}\n", | |
".rimage .center {\n", | |
" text-align: center;\n", | |
"}\n", | |
".hl.num {\n", | |
" color: #AF0F91;\n", | |
"}\n", | |
".hl.str {\n", | |
" color: #317ECC;\n", | |
"}\n", | |
".hl.com {\n", | |
" color: #AD95AF;\n", | |
" font-style: italic;\n", | |
"}\n", | |
".hl.opt {\n", | |
" color: #000000;\n", | |
"}\n", | |
".hl.std {\n", | |
" color: #585858;\n", | |
"}\n", | |
".hl.kwa {\n", | |
" color: #295F94;\n", | |
" font-weight: bold;\n", | |
"}\n", | |
".hl.kwb {\n", | |
" color: #B05A65;\n", | |
"}\n", | |
".hl.kwc {\n", | |
" color: #55aa55;\n", | |
"}\n", | |
".hl.kwd {\n", | |
" color: #BC5A65;\n", | |
" font-weight: bold;\n", | |
"}</style>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"display_highlight_css <- function(theme = 'default') {\n", | |
" requireNamespace('highr', quietly = TRUE)\n", | |
" options(repr.function.highlight = TRUE)\n", | |
" knitr::opts_knit$set(out.format = 'html')\n", | |
" css <- knitr::knit_theme$get(theme)$highlight\n", | |
" IRdisplay::display_html(paste0('<style>', css, '</style>'))\n", | |
"}\n", | |
"display_highlight_css()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"options(\n", | |
" repr.plot.width = 2, repr.plot.height = 2,\n", | |
" jupyter.plot_mimetypes = 'image/svg+xml')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 36, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"GeomRangeFrame <- ggthemes:::GeomRangeFrame" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 69, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<pre class=language-r><code><span class=\"hl kwa\">function</span> <span class=\"hl std\">(</span><span class=\"hl kwc\">data</span><span class=\"hl std\">,</span> <span class=\"hl kwc\">panel_scales</span><span class=\"hl std\">,</span> <span class=\"hl kwc\">coord</span><span class=\"hl std\">,</span> <span class=\"hl kwc\">sides</span> <span class=\"hl std\">=</span> <span class=\"hl str\">"bl"</span><span class=\"hl std\">)</span>\n", | |
"<span class=\"hl std\">{</span>\n", | |
" <span class=\"hl std\">rugs</span> <span class=\"hl kwb\"><-</span> <span class=\"hl kwd\">list</span><span class=\"hl std\">()</span>\n", | |
" <span class=\"hl std\">data</span> <span class=\"hl kwb\"><-</span> <span class=\"hl std\">coord[[</span><span class=\"hl str\">"transform"</span><span class=\"hl std\">]](data, panel_scales)</span>\n", | |
" <span class=\"hl std\">gp</span> <span class=\"hl kwb\"><-</span> <span class=\"hl kwd\">gpar</span><span class=\"hl std\">(</span><span class=\"hl kwc\">col</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">alpha</span><span class=\"hl std\">(data[[</span><span class=\"hl str\">"colour"</span><span class=\"hl std\">]], data[[</span><span class=\"hl str\">"alpha"</span><span class=\"hl std\">]]),</span>\n", | |
" <span class=\"hl kwc\">lty</span> <span class=\"hl std\">= data[[</span><span class=\"hl str\">"linetype"</span><span class=\"hl std\">]],</span> <span class=\"hl kwc\">lwd</span> <span class=\"hl std\">= data[[</span><span class=\"hl str\">"size"</span><span class=\"hl std\">]]</span> <span class=\"hl opt\">*</span> <span class=\"hl std\">.pt)</span>\n", | |
" <span class=\"hl kwa\">if</span> <span class=\"hl std\">(</span><span class=\"hl opt\">!</span><span class=\"hl kwd\">is.null</span><span class=\"hl std\">(data[[</span><span class=\"hl str\">"x"</span><span class=\"hl std\">]])) {</span>\n", | |
" <span class=\"hl kwa\">if</span> <span class=\"hl std\">(</span><span class=\"hl kwd\">grepl</span><span class=\"hl std\">(</span><span class=\"hl str\">"b"</span><span class=\"hl std\">, sides)) {</span>\n", | |
" <span class=\"hl std\">rugs[[</span><span class=\"hl str\">"x_b"</span><span class=\"hl std\">]]</span> <span class=\"hl kwb\"><-</span> <span class=\"hl kwd\">segmentsGrob</span><span class=\"hl std\">(</span><span class=\"hl kwc\">x0</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl kwd\">min</span><span class=\"hl std\">(data[[</span><span class=\"hl str\">"x"</span><span class=\"hl std\">]]),</span>\n", | |
" <span class=\"hl str\">"native"</span><span class=\"hl std\">),</span> <span class=\"hl kwc\">x1</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl kwd\">max</span><span class=\"hl std\">(data[[</span><span class=\"hl str\">"x"</span><span class=\"hl std\">]]),</span> <span class=\"hl str\">"native"</span><span class=\"hl std\">),</span>\n", | |
" <span class=\"hl kwc\">y0</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl num\">0</span><span class=\"hl std\">,</span> <span class=\"hl str\">"npc"</span><span class=\"hl std\">),</span> <span class=\"hl kwc\">y1</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl num\">0</span><span class=\"hl std\">,</span> <span class=\"hl str\">"npc"</span><span class=\"hl std\">),</span> <span class=\"hl kwc\">gp</span> <span class=\"hl std\">= gp)</span>\n", | |
" <span class=\"hl std\">}</span>\n", | |
" <span class=\"hl kwa\">if</span> <span class=\"hl std\">(</span><span class=\"hl kwd\">grepl</span><span class=\"hl std\">(</span><span class=\"hl str\">"t"</span><span class=\"hl std\">, sides)) {</span>\n", | |
" <span class=\"hl std\">rugs[[</span><span class=\"hl str\">"x_t"</span><span class=\"hl std\">]]</span> <span class=\"hl kwb\"><-</span> <span class=\"hl kwd\">segmentsGrob</span><span class=\"hl std\">(</span><span class=\"hl kwc\">x0</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl kwd\">min</span><span class=\"hl std\">(data[[</span><span class=\"hl str\">"x"</span><span class=\"hl std\">]]),</span>\n", | |
" <span class=\"hl str\">"native"</span><span class=\"hl std\">),</span> <span class=\"hl kwc\">x1</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl kwd\">max</span><span class=\"hl std\">(data[[</span><span class=\"hl str\">"x"</span><span class=\"hl std\">]]),</span> <span class=\"hl str\">"native"</span><span class=\"hl std\">),</span>\n", | |
" <span class=\"hl kwc\">y0</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl num\">1</span><span class=\"hl std\">,</span> <span class=\"hl str\">"npc"</span><span class=\"hl std\">),</span> <span class=\"hl kwc\">y1</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl num\">1</span><span class=\"hl std\">,</span> <span class=\"hl str\">"npc"</span><span class=\"hl std\">),</span> <span class=\"hl kwc\">gp</span> <span class=\"hl std\">= gp)</span>\n", | |
" <span class=\"hl std\">}</span>\n", | |
" <span class=\"hl std\">}</span>\n", | |
" <span class=\"hl kwa\">if</span> <span class=\"hl std\">(</span><span class=\"hl opt\">!</span><span class=\"hl kwd\">is.null</span><span class=\"hl std\">(data[[</span><span class=\"hl str\">"y"</span><span class=\"hl std\">]])) {</span>\n", | |
" <span class=\"hl kwa\">if</span> <span class=\"hl std\">(</span><span class=\"hl kwd\">grepl</span><span class=\"hl std\">(</span><span class=\"hl str\">"l"</span><span class=\"hl std\">, sides)) {</span>\n", | |
" <span class=\"hl std\">rugs[[</span><span class=\"hl str\">"y_l"</span><span class=\"hl std\">]]</span> <span class=\"hl kwb\"><-</span> <span class=\"hl kwd\">segmentsGrob</span><span class=\"hl std\">(</span><span class=\"hl kwc\">y0</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl kwd\">min</span><span class=\"hl std\">(data[[</span><span class=\"hl str\">"y"</span><span class=\"hl std\">]]),</span>\n", | |
" <span class=\"hl str\">"native"</span><span class=\"hl std\">),</span> <span class=\"hl kwc\">y1</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl kwd\">max</span><span class=\"hl std\">(data[[</span><span class=\"hl str\">"y"</span><span class=\"hl std\">]]),</span> <span class=\"hl str\">"native"</span><span class=\"hl std\">),</span>\n", | |
" <span class=\"hl kwc\">x0</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl num\">0</span><span class=\"hl std\">,</span> <span class=\"hl str\">"npc"</span><span class=\"hl std\">),</span> <span class=\"hl kwc\">x1</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl num\">0</span><span class=\"hl std\">,</span> <span class=\"hl str\">"npc"</span><span class=\"hl std\">),</span> <span class=\"hl kwc\">gp</span> <span class=\"hl std\">= gp)</span>\n", | |
" <span class=\"hl std\">}</span>\n", | |
" <span class=\"hl kwa\">if</span> <span class=\"hl std\">(</span><span class=\"hl kwd\">grepl</span><span class=\"hl std\">(</span><span class=\"hl str\">"r"</span><span class=\"hl std\">, sides)) {</span>\n", | |
" <span class=\"hl std\">rugs[[</span><span class=\"hl str\">"y_r"</span><span class=\"hl std\">]]</span> <span class=\"hl kwb\"><-</span> <span class=\"hl kwd\">segmentsGrob</span><span class=\"hl std\">(</span><span class=\"hl kwc\">y0</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl kwd\">min</span><span class=\"hl std\">(data[[</span><span class=\"hl str\">"y"</span><span class=\"hl std\">]]),</span>\n", | |
" <span class=\"hl str\">"native"</span><span class=\"hl std\">),</span> <span class=\"hl kwc\">y1</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl kwd\">max</span><span class=\"hl std\">(data[[</span><span class=\"hl str\">"y"</span><span class=\"hl std\">]]),</span> <span class=\"hl str\">"native"</span><span class=\"hl std\">),</span>\n", | |
" <span class=\"hl kwc\">x0</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl num\">1</span><span class=\"hl std\">,</span> <span class=\"hl str\">"npc"</span><span class=\"hl std\">),</span> <span class=\"hl kwc\">x1</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">unit</span><span class=\"hl std\">(</span><span class=\"hl num\">1</span><span class=\"hl std\">,</span> <span class=\"hl str\">"npc"</span><span class=\"hl std\">),</span> <span class=\"hl kwc\">gp</span> <span class=\"hl std\">= gp)</span>\n", | |
" <span class=\"hl std\">}</span>\n", | |
" <span class=\"hl std\">}</span>\n", | |
" <span class=\"hl kwd\">gTree</span><span class=\"hl std\">(</span><span class=\"hl kwc\">children</span> <span class=\"hl std\">=</span> <span class=\"hl kwd\">do.call</span><span class=\"hl std\">(</span><span class=\"hl str\">"gList"</span><span class=\"hl std\">, rugs))</span>\n", | |
"<span class=\"hl std\">}</span></code></pre>" | |
], | |
"text/latex": [ | |
"\\hlkwa{function} \\hlstd{(}\\hlkwc{data}\\hlstd{,} \\hlkwc{panel_scales}\\hlstd{,} \\hlkwc{coord}\\hlstd{,} \\hlkwc{sides} \\hlstd{=} \\hlstr{\"bl\"}\\hlstd{)}\n", | |
"\\hlstd{\\{}\n", | |
" \\hlstd{rugs} \\hlkwb{<-} \\hlkwd{list}\\hlstd{()}\n", | |
" \\hlstd{data} \\hlkwb{<-} \\hlstd{coord[[}\\hlstr{\"transform\"}\\hlstd{]](data, panel_scales)}\n", | |
" \\hlstd{gp} \\hlkwb{<-} \\hlkwd{gpar}\\hlstd{(}\\hlkwc{col} \\hlstd{=} \\hlkwd{alpha}\\hlstd{(data[[}\\hlstr{\"colour\"}\\hlstd{]], data[[}\\hlstr{\"alpha\"}\\hlstd{]]),}\n", | |
" \\hlkwc{lty} \\hlstd{= data[[}\\hlstr{\"linetype\"}\\hlstd{]],} \\hlkwc{lwd} \\hlstd{= data[[}\\hlstr{\"size\"}\\hlstd{]]} \\hlopt{*} \\hlstd{.pt)}\n", | |
" \\hlkwa{if} \\hlstd{(}\\hlopt{!}\\hlkwd{is.null}\\hlstd{(data[[}\\hlstr{\"x\"}\\hlstd{]])) \\{}\n", | |
" \\hlkwa{if} \\hlstd{(}\\hlkwd{grepl}\\hlstd{(}\\hlstr{\"b\"}\\hlstd{, sides)) \\{}\n", | |
" \\hlstd{rugs[[}\\hlstr{\"x_b\"}\\hlstd{]]} \\hlkwb{<-} \\hlkwd{segmentsGrob}\\hlstd{(}\\hlkwc{x0} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlkwd{min}\\hlstd{(data[[}\\hlstr{\"x\"}\\hlstd{]]),}\n", | |
" \\hlstr{\"native\"}\\hlstd{),} \\hlkwc{x1} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlkwd{max}\\hlstd{(data[[}\\hlstr{\"x\"}\\hlstd{]]),} \\hlstr{\"native\"}\\hlstd{),}\n", | |
" \\hlkwc{y0} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlnum{0}\\hlstd{,} \\hlstr{\"npc\"}\\hlstd{),} \\hlkwc{y1} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlnum{0}\\hlstd{,} \\hlstr{\"npc\"}\\hlstd{),} \\hlkwc{gp} \\hlstd{= gp)}\n", | |
" \\hlstd{\\}}\n", | |
" \\hlkwa{if} \\hlstd{(}\\hlkwd{grepl}\\hlstd{(}\\hlstr{\"t\"}\\hlstd{, sides)) \\{}\n", | |
" \\hlstd{rugs[[}\\hlstr{\"x_t\"}\\hlstd{]]} \\hlkwb{<-} \\hlkwd{segmentsGrob}\\hlstd{(}\\hlkwc{x0} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlkwd{min}\\hlstd{(data[[}\\hlstr{\"x\"}\\hlstd{]]),}\n", | |
" \\hlstr{\"native\"}\\hlstd{),} \\hlkwc{x1} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlkwd{max}\\hlstd{(data[[}\\hlstr{\"x\"}\\hlstd{]]),} \\hlstr{\"native\"}\\hlstd{),}\n", | |
" \\hlkwc{y0} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlnum{1}\\hlstd{,} \\hlstr{\"npc\"}\\hlstd{),} \\hlkwc{y1} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlnum{1}\\hlstd{,} \\hlstr{\"npc\"}\\hlstd{),} \\hlkwc{gp} \\hlstd{= gp)}\n", | |
" \\hlstd{\\}}\n", | |
" \\hlstd{\\}}\n", | |
" \\hlkwa{if} \\hlstd{(}\\hlopt{!}\\hlkwd{is.null}\\hlstd{(data[[}\\hlstr{\"y\"}\\hlstd{]])) \\{}\n", | |
" \\hlkwa{if} \\hlstd{(}\\hlkwd{grepl}\\hlstd{(}\\hlstr{\"l\"}\\hlstd{, sides)) \\{}\n", | |
" \\hlstd{rugs[[}\\hlstr{\"y_l\"}\\hlstd{]]} \\hlkwb{<-} \\hlkwd{segmentsGrob}\\hlstd{(}\\hlkwc{y0} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlkwd{min}\\hlstd{(data[[}\\hlstr{\"y\"}\\hlstd{]]),}\n", | |
" \\hlstr{\"native\"}\\hlstd{),} \\hlkwc{y1} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlkwd{max}\\hlstd{(data[[}\\hlstr{\"y\"}\\hlstd{]]),} \\hlstr{\"native\"}\\hlstd{),}\n", | |
" \\hlkwc{x0} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlnum{0}\\hlstd{,} \\hlstr{\"npc\"}\\hlstd{),} \\hlkwc{x1} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlnum{0}\\hlstd{,} \\hlstr{\"npc\"}\\hlstd{),} \\hlkwc{gp} \\hlstd{= gp)}\n", | |
" \\hlstd{\\}}\n", | |
" \\hlkwa{if} \\hlstd{(}\\hlkwd{grepl}\\hlstd{(}\\hlstr{\"r\"}\\hlstd{, sides)) \\{}\n", | |
" \\hlstd{rugs[[}\\hlstr{\"y_r\"}\\hlstd{]]} \\hlkwb{<-} \\hlkwd{segmentsGrob}\\hlstd{(}\\hlkwc{y0} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlkwd{min}\\hlstd{(data[[}\\hlstr{\"y\"}\\hlstd{]]),}\n", | |
" \\hlstr{\"native\"}\\hlstd{),} \\hlkwc{y1} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlkwd{max}\\hlstd{(data[[}\\hlstr{\"y\"}\\hlstd{]]),} \\hlstr{\"native\"}\\hlstd{),}\n", | |
" \\hlkwc{x0} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlnum{1}\\hlstd{,} \\hlstr{\"npc\"}\\hlstd{),} \\hlkwc{x1} \\hlstd{=} \\hlkwd{unit}\\hlstd{(}\\hlnum{1}\\hlstd{,} \\hlstr{\"npc\"}\\hlstd{),} \\hlkwc{gp} \\hlstd{= gp)}\n", | |
" \\hlstd{\\}}\n", | |
" \\hlstd{\\}}\n", | |
" \\hlkwd{gTree}\\hlstd{(}\\hlkwc{children} \\hlstd{=} \\hlkwd{do.call}\\hlstd{(}\\hlstr{\"gList\"}\\hlstd{, rugs))}\n", | |
"\\hlstd{\\}}" | |
], | |
"text/markdown": [ | |
"```r\n", | |
"function (data, panel_scales, coord, sides = \"bl\") \n", | |
"{\n", | |
" rugs <- list()\n", | |
" data <- coord[[\"transform\"]](data, panel_scales)\n", | |
" gp <- gpar(col = alpha(data[[\"colour\"]], data[[\"alpha\"]]), \n", | |
" lty = data[[\"linetype\"]], lwd = data[[\"size\"]] * .pt)\n", | |
" if (!is.null(data[[\"x\"]])) {\n", | |
" if (grepl(\"b\", sides)) {\n", | |
" rugs[[\"x_b\"]] <- segmentsGrob(x0 = unit(min(data[[\"x\"]]), \n", | |
" \"native\"), x1 = unit(max(data[[\"x\"]]), \"native\"), \n", | |
" y0 = unit(0, \"npc\"), y1 = unit(0, \"npc\"), gp = gp)\n", | |
" }\n", | |
" if (grepl(\"t\", sides)) {\n", | |
" rugs[[\"x_t\"]] <- segmentsGrob(x0 = unit(min(data[[\"x\"]]), \n", | |
" \"native\"), x1 = unit(max(data[[\"x\"]]), \"native\"), \n", | |
" y0 = unit(1, \"npc\"), y1 = unit(1, \"npc\"), gp = gp)\n", | |
" }\n", | |
" }\n", | |
" if (!is.null(data[[\"y\"]])) {\n", | |
" if (grepl(\"l\", sides)) {\n", | |
" rugs[[\"y_l\"]] <- segmentsGrob(y0 = unit(min(data[[\"y\"]]), \n", | |
" \"native\"), y1 = unit(max(data[[\"y\"]]), \"native\"), \n", | |
" x0 = unit(0, \"npc\"), x1 = unit(0, \"npc\"), gp = gp)\n", | |
" }\n", | |
" if (grepl(\"r\", sides)) {\n", | |
" rugs[[\"y_r\"]] <- segmentsGrob(y0 = unit(min(data[[\"y\"]]), \n", | |
" \"native\"), y1 = unit(max(data[[\"y\"]]), \"native\"), \n", | |
" x0 = unit(1, \"npc\"), x1 = unit(1, \"npc\"), gp = gp)\n", | |
" }\n", | |
" }\n", | |
" gTree(children = do.call(\"gList\", rugs))\n", | |
"}\n", | |
"```" | |
], | |
"text/plain": [ | |
"function (data, panel_scales, coord, sides = \"bl\") \n", | |
"{\n", | |
" rugs <- list()\n", | |
" data <- coord[[\"transform\"]](data, panel_scales)\n", | |
" gp <- gpar(col = alpha(data[[\"colour\"]], data[[\"alpha\"]]), \n", | |
" lty = data[[\"linetype\"]], lwd = data[[\"size\"]] * .pt)\n", | |
" if (!is.null(data[[\"x\"]])) {\n", | |
" if (grepl(\"b\", sides)) {\n", | |
" rugs[[\"x_b\"]] <- segmentsGrob(x0 = unit(min(data[[\"x\"]]), \n", | |
" \"native\"), x1 = unit(max(data[[\"x\"]]), \"native\"), \n", | |
" y0 = unit(0, \"npc\"), y1 = unit(0, \"npc\"), gp = gp)\n", | |
" }\n", | |
" if (grepl(\"t\", sides)) {\n", | |
" rugs[[\"x_t\"]] <- segmentsGrob(x0 = unit(min(data[[\"x\"]]), \n", | |
" \"native\"), x1 = unit(max(data[[\"x\"]]), \"native\"), \n", | |
" y0 = unit(1, \"npc\"), y1 = unit(1, \"npc\"), gp = gp)\n", | |
" }\n", | |
" }\n", | |
" if (!is.null(data[[\"y\"]])) {\n", | |
" if (grepl(\"l\", sides)) {\n", | |
" rugs[[\"y_l\"]] <- segmentsGrob(y0 = unit(min(data[[\"y\"]]), \n", | |
" \"native\"), y1 = unit(max(data[[\"y\"]]), \"native\"), \n", | |
" x0 = unit(0, \"npc\"), x1 = unit(0, \"npc\"), gp = gp)\n", | |
" }\n", | |
" if (grepl(\"r\", sides)) {\n", | |
" rugs[[\"y_r\"]] <- segmentsGrob(y0 = unit(min(data[[\"y\"]]), \n", | |
" \"native\"), y1 = unit(max(data[[\"y\"]]), \"native\"), \n", | |
" x0 = unit(1, \"npc\"), x1 = unit(1, \"npc\"), gp = gp)\n", | |
" }\n", | |
" }\n", | |
" gTree(children = do.call(\"gList\", rugs))\n", | |
"}\n", | |
"<environment: namespace:ggthemes>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"environment(GeomRangeFrame$draw_panel)$f" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 62, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"draw_angle <- function(gp = NULL) grid.drawgTree(children = gList(\n", | |
" segmentsGrob(x0 = unit(0, 'npc'), x1 = unit(0, 'npc'), y0 = unit(0, 'native'), y1 = unit(144, 'native'), gp = gp),\n", | |
" segmentsGrob(y0 = unit(0, 'npc'), y1 = unit(0, 'npc'), x0 = unit(0, 'native'), x1 = unit(144, 'native'), gp = gp)\n", | |
"))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 66, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/svg+xml": [ | |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", | |
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"144pt\" height=\"144pt\" viewBox=\"0 0 144 144\" version=\"1.1\">\n", | |
"<g id=\"surface209\">\n", | |
"<rect x=\"0\" y=\"0\" width=\"144\" height=\"144\" style=\"fill:rgb(100%,100%,100%);fill-opacity:1;stroke:none;\"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 0 0 L 0 144 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 0 144 L 144 144 \"/>\n", | |
"</g>\n", | |
"</svg>\n" | |
] | |
}, | |
"metadata": { | |
"image/svg+xml": { | |
"isolated": true | |
} | |
}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"draw_angle() %>% grid.draw" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 65, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/svg+xml": [ | |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", | |
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"144pt\" height=\"144pt\" viewBox=\"0 0 144 144\" version=\"1.1\">\n", | |
"<g id=\"surface202\">\n", | |
"<rect x=\"0\" y=\"0\" width=\"144\" height=\"144\" style=\"fill:rgb(100%,100%,100%);fill-opacity:1;stroke:none;\"/>\n", | |
"<path style=\"fill:none;stroke-width:1.422638;stroke-linecap:round;stroke-linejoin:round;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 0 0 L 0 144 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1.422638;stroke-linecap:round;stroke-linejoin:round;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 0 144 L 144 144 \"/>\n", | |
"</g>\n", | |
"</svg>\n" | |
] | |
}, | |
"metadata": { | |
"image/svg+xml": { | |
"isolated": true | |
} | |
}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"GeomRangeFrame$default_aes %>%\n", | |
" with(gpar(lty = linetype, lwd = size * .pt)) %>%\n", | |
" draw_angle %>%\n", | |
" grid.draw" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "R", | |
"language": "R", | |
"name": "ir" | |
}, | |
"language_info": { | |
"codemirror_mode": "r", | |
"file_extension": ".r", | |
"mimetype": "text/x-r-source", | |
"name": "R", | |
"pygments_lexer": "r", | |
"version": "3.4.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment