Skip to content

Instantly share code, notes, and snippets.

@gadenbuie
Forked from emitanaka/ggplot_tutorial.Rmd
Created September 24, 2018 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gadenbuie/634060984f0007bf390a931dd3b31bab to your computer and use it in GitHub Desktop.
Save gadenbuie/634060984f0007bf390a931dd3b31bab to your computer and use it in GitHub Desktop.
ggplot tutorial with kunoichi + ninjutsu xaringan theme
---
title: "ggplot tutorial"
subtitle: "with kunoichi + ninjutsu theme"
author: "<br><br> Emi Tanaka"
date: "<br>2018/09/16"
output:
xaringan::moon_reader:
lib_dir: libs
css: ["kunoichi", "ninjutsu"]
nature:
ratio: "16:9"
highlightLines: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=TRUE)
knitr::opts_chunk$set(fig.height=6, out.width="100%")
library(ggplot2)
# reveal lines up to `upto` and highlight lines `highlight`
reveal <- function(name, upto, highlight = upto) {
content <- knitr:::knit_code$get(name)
content[upto] <- gsub("+", "", content[upto], fixed=T)
content[highlight] <- paste(content[highlight], "#<<")
content[1:upto]
}
partial_knit_chunks <- function(chunk_name) {
# Create slide for lines 1:N for each line N in the given chunk
idx_lines <- seq_along(knitr:::knit_code$get(chunk_name))
partial_knit_steps <- glue::glue(
"class: split-40",
"count: false",
"",
".column[.content[",
"```{r plot{{idx_lines}}, eval=FALSE, code=reveal('{{chunk_name}}', {{idx_lines}})}",
"```",
"]]",
".column[.content.center[",
"```{r output{{idx_lines}}, echo=FALSE, code=reveal('{{chunk_name}}', {{idx_lines}})}",
"```",
"]]",
.open = "{{", .close = "}}", .sep = "\n"
)
glue::glue_collapse(partial_knit_steps, "\n---\n")
}
```
```{r complete, eval=F, echo=F}
ggplot(iris) +
aes(Sepal.Length, Sepal.Width) +
geom_point() +
labs(x = "Sepal Length") +
labs(y = "Sepal Width") +
labs(title="The famous iris data") +
labs(subtitle="Data collected by Anderson, Edgar (1935)") +
aes(color= Species) +
theme_bw(base_size=16)
```
`r paste(knitr::knit(text = partial_knit_chunks("complete")), collapse = "\n")`
<!--
Create slides for the "complete" chunk
...it's just R Markdown as a vector of strings
...and why not be super concise about it?
-->
<!-- This css chunk can't be before the first class: split-40... lines -->
```{css, eval=TRUE}
.remark-code{ line-height: 2; }
```
@dmi3kno
Copy link

dmi3kno commented Oct 15, 2020

This is super cool. Thanks for the idea with knitr::knit(text)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment