Communicate wrap up (#1136)
* Workflow update * Edit Quarto formats * Finish edits to formats + move quarto pngs * Update intro + fix typos * Update status
This commit is contained in:
parent
9b592e7680
commit
7ff2b15021
|
@ -6,7 +6,7 @@
|
|||
source("_common.R")
|
||||
```
|
||||
|
||||
So far, you've learned the tools to get your data into R, tidy it into a form convenient for analysis, and then understand your data through transformation, and visualisation.
|
||||
So far, you've learned the tools to get your data into R, tidy it into a form convenient for analysis, and then understand your data through transformation, and visualization.
|
||||
However, it doesn't matter how great your analysis is unless you can explain it to others: you need to **communicate** your results.
|
||||
|
||||
```{r}
|
||||
|
@ -24,17 +24,15 @@ However, it doesn't matter how great your analysis is unless you can explain it
|
|||
knitr::include_graphics("diagrams/data-science/communicate.png", dpi = 270)
|
||||
```
|
||||
|
||||
Communication is the theme of the following four chapters:
|
||||
Communication is the theme of the following three chapters:
|
||||
|
||||
- In \[R Markdown\], you will learn about R Markdown, a tool for integrating prose, code, and results.
|
||||
You can use R Markdown in notebook mode for analyst-to-analyst communication, and in report mode for analyst-to-decision-maker communication.
|
||||
Thanks to the power of R Markdown formats, you can even use the same document for both purposes.
|
||||
- In @sec-quarto, you will learn about Quarto, a tool for integrating prose, code, and results.
|
||||
You can use Quarto for analyst-to-analyst communication as well as analyst-to-decision-maker communication.
|
||||
Thanks to the power of Quarto formats, you can even use the same document for both purposes.
|
||||
|
||||
- In \[Graphics for communication\], you will learn how to take your exploratory graphics and turn them into expository graphics, graphics that help the newcomer to your analysis understand what's going on as quickly and easily as possible.
|
||||
- In @sec-quarto-formats, you'll learn a little about the many other varieties of outputs you can produce using Quarto, including dashboards, websites, and books.
|
||||
|
||||
- In \[R Markdown formats\], you'll learn a little about the many other varieties of outputs you can produce using R Markdown, including dashboards, websites, and books.
|
||||
- We'll finish up with @sec-quarto-workflow, where you'll learn about the "analysis notebook" and how to systematically record your successes and failures so that you can learn from them.
|
||||
|
||||
- We'll finish up with \[R Markdown workflow\], where you'll learn about the "analysis notebook" and how to systematically record your successes and failures so that you can learn from them.
|
||||
|
||||
Unfortunately, these chapters focus mostly on the technical mechanics of communication, not the really hard problems of communicating your thoughts to other humans.
|
||||
These chapters focus mostly on the technical mechanics of communication, not the really hard problems of communicating your thoughts to other humans.
|
||||
However, there are lot of other great books about communication, which we'll point you to at the end of each chapter.
|
||||
|
|
|
@ -4,54 +4,51 @@
|
|||
#| results: "asis"
|
||||
#| echo: false
|
||||
source("_common.R")
|
||||
status("drafting")
|
||||
status("polishing")
|
||||
```
|
||||
|
||||
## Introduction
|
||||
|
||||
So far you've seen R Markdown used to produce HTML documents.
|
||||
This chapter gives a brief overview of some of the many other types of output you can produce with R Markdown.
|
||||
So far you've seen Quarto used to produce HTML documents.
|
||||
This chapter gives a brief overview of some of the many other types of output you can produce with Quarto.
|
||||
|
||||
There are two ways to set the output of a document:
|
||||
|
||||
1. Permanently, by modifying the YAML header:
|
||||
|
||||
``` yaml
|
||||
title: "Viridis Demo"
|
||||
output: html_document
|
||||
title: "Diamond sizes"
|
||||
format: html
|
||||
```
|
||||
|
||||
2. Transiently, by calling `rmarkdown::render()` by hand:
|
||||
2. Transiently, by calling `quarto::quarto_render()` by hand:
|
||||
|
||||
```{r eval = FALSE}
|
||||
rmarkdown::render("diamond-sizes.Rmd", output_format = "word_document")
|
||||
```{r}
|
||||
#| eval: false
|
||||
|
||||
quarto::quarto_render("diamond-sizes.qmd", output_format = "docx")
|
||||
```
|
||||
|
||||
This is useful if you want to programmatically produce multiple types of output.
|
||||
This is useful if you want to programmatically produce multiple types of output since the `output_format` argument can also take a list of values.
|
||||
|
||||
RStudio's knit button renders a file to the first format listed in its `output` field.
|
||||
You can render to additional formats by clicking the dropdown menu beside the knit button.
|
||||
```{r}
|
||||
#| eval: false
|
||||
|
||||
```{r}
|
||||
#| echo: false
|
||||
#| out-width: null
|
||||
|
||||
knitr::include_graphics("screenshots/rmarkdown-knit.png")
|
||||
```
|
||||
quarto::quarto_render("diamond-sizes.qmd", output_format = c("docx", "pdf"))
|
||||
```
|
||||
|
||||
## Output options
|
||||
|
||||
Each output format is associated with an R function.
|
||||
You can either write `foo` or `pkg::foo`.
|
||||
If you omit `pkg`, the default is assumed to be rmarkdown.
|
||||
It's important to know the name of the function that makes the output because that's where you get help.
|
||||
For example, to figure out what parameters you can set with `html_document`, look at `?rmarkdown::html_document`.
|
||||
Quarto offers a wide range of output formats.
|
||||
You can find the complete list at <https://quarto.org/docs/output-formats/all-formats.html>.
|
||||
Many formats share some output options (e.g., `toc: true` for including a table of contents), but others have options that are format specific (e.g., `code-fold: true` collapses code chunks into a `<details>` tag for HTML output so the user can display it on demand, it's not applicable in a PDF or Word document).
|
||||
|
||||
To override the default parameter values, you need to use an expanded `output` field.
|
||||
For example, if you wanted to render an `html_document` with a floating table of contents, you'd use:
|
||||
To override the default voptions, you need to use an expanded `format` field.
|
||||
For example, if you wanted to render an `html` with a floating table of contents, you'd use:
|
||||
|
||||
``` yaml
|
||||
output:
|
||||
html_document:
|
||||
format:
|
||||
html:
|
||||
toc: true
|
||||
toc_float: true
|
||||
```
|
||||
|
@ -59,143 +56,111 @@ output:
|
|||
You can even render to multiple outputs by supplying a list of formats:
|
||||
|
||||
``` yaml
|
||||
output:
|
||||
html_document:
|
||||
format:
|
||||
html:
|
||||
toc: true
|
||||
toc_float: true
|
||||
pdf_document: default
|
||||
pdf: default
|
||||
docx: default
|
||||
```
|
||||
|
||||
Note the special syntax if you don't want to override any of the default options.
|
||||
Note the special syntax (`pdf: default`) if you don't want to override any of the default options.
|
||||
|
||||
## Documents
|
||||
|
||||
The previous chapter focused on the default `html_document` output.
|
||||
There are a number of basic variations on that theme, generating different types of documents:
|
||||
|
||||
- `pdf_document` makes a PDF with LaTeX (an open source document layout system), which you'll need to install.
|
||||
RStudio will prompt you if you don't already have it.
|
||||
|
||||
- `word_document` for Microsoft Word documents (`.docx`).
|
||||
|
||||
- `odt_document` for OpenDocument Text documents (`.odt`).
|
||||
|
||||
- `rtf_document` for Rich Text Format (`.rtf`) documents.
|
||||
|
||||
- `md_document` for a Markdown document.
|
||||
This isn't typically useful by itself, but you might use it if, for example, your corporate CMS or lab wiki uses markdown.
|
||||
|
||||
- `github_document`: this is a tailored version of `md_document` designed for sharing on GitHub.
|
||||
|
||||
Remember, when generating a document to share with decision makers, you can turn off the default display of code by setting global options in the setup chunk:
|
||||
To render to all formats specified in the YAML of a document, you can use `output_format = "all"`.
|
||||
|
||||
```{r}
|
||||
#| eval: false
|
||||
|
||||
knitr::opts_chunk$set(echo = FALSE)
|
||||
quarto::quarto_render("diamond-sizes.qmd", output_format = "all")
|
||||
```
|
||||
|
||||
For `html_document`s another option is to make the code chunks hidden by default, but visible with a click:
|
||||
## Documents
|
||||
|
||||
The previous chapter focused on the default `html` output.
|
||||
There are a number of basic variations on that theme, generating different types of documents.
|
||||
For example:
|
||||
|
||||
- `pdf` makes a PDF with LaTeX (an open source document layout system), which you'll need to install.
|
||||
RStudio will prompt you if you don't already have it.
|
||||
|
||||
- `docx` for Microsoft Word (`.docx`) documents.
|
||||
|
||||
- `odt` for OpenDocument Text (`.odt`) documents.
|
||||
|
||||
- `rtf` for Rich Text Format (`.rtf`) documents.
|
||||
|
||||
- `gfm` for a GitHub Flavored Markdown (`.md`) document.
|
||||
|
||||
- `ipynb` for Jupyter Notebooks (`.ipynb`).
|
||||
|
||||
Remember, when generating a document to share with decision makers, you can turn off the default display of code by setting global options in document YAML:
|
||||
|
||||
``` yaml
|
||||
output:
|
||||
html_document:
|
||||
code_folding: hide
|
||||
execute:
|
||||
echo: false
|
||||
```
|
||||
|
||||
## Notebooks
|
||||
|
||||
A notebook, `html_notebook`, is a variation on a `html_document`.
|
||||
The rendered outputs are very similar, but the purpose is different.
|
||||
A `html_document` is focused on communicating with decision makers, while a notebook is focused on collaborating with other data scientists.
|
||||
These different purposes lead to using the HTML output in different ways.
|
||||
Both HTML outputs will contain the fully rendered output, but the notebook also contains the full source code.
|
||||
That means you can use the `.nb.html` generated by the notebook in two ways:
|
||||
|
||||
1. You can view it in a web browser, and see the rendered output.
|
||||
Unlike `html_document`, this rendering always includes an embedded copy of the source code that generated it.
|
||||
|
||||
2. You can edit it in RStudio.
|
||||
When you open an `.nb.html` file, RStudio will automatically recreate the `.Rmd` file that generated it.
|
||||
In the future, you will also be able to include supporting files (e.g. `.csv` data files), which will be automatically extracted when needed.
|
||||
|
||||
Emailing `.nb.html` files is a simple way to share analyses with your colleagues.
|
||||
But things will get painful as soon as they want to make changes.
|
||||
If this starts to happen, it's a good time to learn Git and GitHub.
|
||||
Learning Git and GitHub is definitely painful at first, but the collaboration payoff is huge.
|
||||
As mentioned earlier, Git and GitHub are outside the scope of the book, but there's one tip that's useful if you're already using them: use both `html_notebook` and `github_document` outputs:
|
||||
For `html` documents another option is to make the code chunks hidden by default, but visible with a click:
|
||||
|
||||
``` yaml
|
||||
output:
|
||||
html_notebook: default
|
||||
github_document: default
|
||||
format:
|
||||
html:
|
||||
code: true
|
||||
```
|
||||
|
||||
`html_notebook` gives you a local preview, and a file that you can share via email.
|
||||
`github_document` creates a minimal md file that you can check into git.
|
||||
You can easily see how the results of your analysis (not just the code) change over time, and GitHub will render it for you nicely online.
|
||||
|
||||
## Presentations
|
||||
|
||||
You can also use R Markdown to produce presentations.
|
||||
You can also use Quarto to produce presentations.
|
||||
You get less visual control than with a tool like Keynote or PowerPoint, but automatically inserting the results of your R code into a presentation can save a huge amount of time.
|
||||
Presentations work by dividing your content into slides, with a new slide beginning at each first (`#`) or second (`##`) level header.
|
||||
You can also insert a horizontal rule (`***`) to create a new slide without a header.
|
||||
Presentations work by dividing your content into slides, with a new slide beginning at each second (`##`) level header.
|
||||
Additionally, first (`#`) level headers can be used to indicate the beginning of a new section with a section title slide that is by default centered in the middle.
|
||||
|
||||
R Markdown comes with three presentation formats built-in:
|
||||
Quarto supports a variety of presentation formats, including:
|
||||
|
||||
1. `ioslides_presentation` - HTML presentation with ioslides
|
||||
1. `revealjs` - HTML presentation with revealjs
|
||||
|
||||
2. `slidy_presentation` - HTML presentation with W3C Slidy
|
||||
2. `pptx` - PowerPoint presentation
|
||||
|
||||
3. `beamer_presentation` - PDF presentation with LaTeX Beamer.
|
||||
3. `beamer` - PDF presentation with LaTeX Beamer.
|
||||
|
||||
Three other popular formats are provided by packages:
|
||||
|
||||
1. **xaringan**, <https://slides.yihui.org/xaringan>, is an R Markdown extension based on the JavaScript library remark.js to generate HTML5 presentations.
|
||||
|
||||
2. `revealjs::revealjs_presentation` - HTML presentation with reveal.js.
|
||||
Requires the **revealjs** package, <https://github.com/rstudio/revealjs>.
|
||||
|
||||
3. **rmdshower**, <https://github.com/MangoTheCat/rmdshower>, provides a wrapper around the **shower**, <https://github.com/shower/shower>, presentation engine
|
||||
You can read more about creating presentations with Quarto at [https://quarto.org/docs/presentations](https://quarto.org/docs/presentations/).
|
||||
|
||||
## Dashboards
|
||||
|
||||
Dashboards are a useful way to communicate large amounts of information visually and quickly.
|
||||
Flexdashboard makes it particularly easy to create dashboards using R Markdown and a convention for how the headers affect the layout:
|
||||
|
||||
- Each level 1 header (`#`) begins a new page in the dashboard.
|
||||
- Each level 2 header (`##`) begins a new column.
|
||||
- Each level 3 header (`###`) begins a new row.
|
||||
A dashboard-like look can be achieved with Quarto using document layout options like sidebars, tabsets, multi-column layouts, etc.
|
||||
|
||||
For example, you can produce this dashboard:
|
||||
|
||||
```{r}
|
||||
#| echo: false
|
||||
#| out-width: "75%"
|
||||
#| fig-alt: |
|
||||
#| Quarto dashboard with the title "Diamonds dashboard". The first
|
||||
#| tab shows four plots of the diamonds dataset. The second tab
|
||||
#| shows summary statistics for price and carat of diamonds. The third
|
||||
#| tab shows an interactive data table of the first 100 diamonds.
|
||||
|
||||
knitr::include_graphics("screenshots/rmarkdown-flexdashboard.png")
|
||||
knitr::include_graphics("quarto/quarto-dashboard.png")
|
||||
```
|
||||
|
||||
Using this code:
|
||||
|
||||
```{r comment = "", echo = FALSE}
|
||||
cat(readr::read_file("quarto/dashboard.Rmd"))
|
||||
cat(readr::read_file("quarto/quarto-dashboard.qmd"))
|
||||
```
|
||||
|
||||
Flexdashboard also provides simple tools for creating sidebars, tabsets, value boxes, and gauges.
|
||||
To learn more about flexdashboard visit <https://pkgs.rstudio.com/flexdashboard>.
|
||||
To learn more about Quarto component layouts, visit <https://quarto.org/docs/interactive/layout.html>.
|
||||
|
||||
## Interactivity
|
||||
|
||||
Any HTML format (document, notebook, presentation, or dashboard) can contain interactive components.
|
||||
Any HTML documents can contain interactive components.
|
||||
|
||||
### htmlwidgets
|
||||
|
||||
HTML is an interactive format, and you can take advantage of that interactivity with **htmlwidgets**, R functions that produce interactive HTML visualisations.
|
||||
HTML is an interactive format, and you can take advantage of that interactivity with **htmlwidgets**, R functions that produce interactive HTML visualizations.
|
||||
For example, take the **leaflet** map below.
|
||||
If you're viewing this page on the web, you can drag the map around, zoom in and out, etc.
|
||||
You obviously can't do that in a book, so rmarkdown automatically inserts a static screenshot for you.
|
||||
You obviously can't do that in a book, so Quarto automatically inserts a static screenshot for you.
|
||||
|
||||
```{r}
|
||||
library(leaflet)
|
||||
|
@ -227,12 +192,12 @@ On one hand, that's great because you can distribute the HTML file without any c
|
|||
However, that fundamentally limits what you can do to things that have been implemented in HTML and JavaScript.
|
||||
An alternative approach is to use **shiny**, a package that allows you to create interactivity using R code, not JavaScript.
|
||||
|
||||
To call Shiny code from an R Markdown document, add `runtime: shiny` to the header:
|
||||
To call Shiny code from an Quarto document, add `server: shiny` to the YAML header:
|
||||
|
||||
``` yaml
|
||||
title: "Shiny Web App"
|
||||
output: html_document
|
||||
runtime: shiny
|
||||
format: html
|
||||
server: shiny
|
||||
```
|
||||
|
||||
Then you can use the "input" functions to add interactive components to the document:
|
||||
|
@ -246,11 +211,16 @@ textInput("name", "What is your name?")
|
|||
numericInput("age", "How old are you?", NA, min = 0, max = 150)
|
||||
```
|
||||
|
||||
And you also need a code chunk with chunk option `context: server` which contains the code that needs to run in a Shiny server.
|
||||
|
||||
```{r}
|
||||
#| echo: false
|
||||
#| out-width: null
|
||||
#| fig-alt: |
|
||||
#| Two input boxes on top of each other. Top one says "What is your
|
||||
#| name?", the bottom one "How old are you?".
|
||||
|
||||
knitr::include_graphics("screenshots/rmarkdown-shiny.png")
|
||||
knitr::include_graphics("quarto/quarto-shiny.png")
|
||||
```
|
||||
|
||||
You can then refer to the values with `input$name` and `input$age`, and the code that uses them will be automatically re-run whenever they change.
|
||||
|
@ -258,44 +228,70 @@ You can then refer to the values with `input$name` and `input$age`, and the code
|
|||
We can't show you a live shiny app here because shiny interactions occur on the **server-side**.
|
||||
This means that you can write interactive apps without knowing JavaScript, but you need a server to run them on.
|
||||
This introduces a logistical issue: Shiny apps need a Shiny server to be run online.
|
||||
When you run shiny apps on your own computer, shiny automatically sets up a shiny server for you, but you need a public facing shiny server if you want to publish this sort of interactivity online.
|
||||
When you run Shiny apps on your own computer, Shiny automatically sets up a Shiny server for you, but you need a public facing Shiny server if you want to publish this sort of interactivity online.
|
||||
That's the fundamental trade-off of shiny: you can do anything in a shiny document that you can do in R, but it requires someone to be running R.
|
||||
|
||||
Learn more about Shiny at <https://shiny.rstudio.com>.
|
||||
For learning more about Shiny, we recommend reading Mastering Shiny by Hadley Wickham, [https://mastering-shiny.org](https://mastering-shiny.org/).
|
||||
|
||||
## Websites
|
||||
## Websites and books
|
||||
|
||||
With a little additional infrastructure you can use R Markdown to generate a complete website:
|
||||
With a little additional infrastructure you can use Quarto to generate a complete website:
|
||||
|
||||
- Put your `.Rmd` files in a single directory.
|
||||
`index.Rmd` will become the home page.
|
||||
- Put your `.qmd` files in a single directory.
|
||||
`index.qmd` will become the home page.
|
||||
|
||||
- Add a YAML file named `_site.yml` provides the navigation for the site.
|
||||
For example:
|
||||
- Add a YAML file named `_quarto.yml` that provides the navigation for the site.
|
||||
In this file, set the `project` type:
|
||||
|
||||
```{r echo = FALSE, comment = ""}
|
||||
cat(readr::read_file("quarto/example-site.yml"))
|
||||
- For a website, set `type: book`:
|
||||
|
||||
``` yaml
|
||||
project:
|
||||
type: book
|
||||
```
|
||||
|
||||
Execute `rmarkdown::render_site()` to build `_site`, a directory of files ready to deploy as a standalone static website, or if you use an RStudio Project for your website directory.
|
||||
RStudio will add a Build tab to the IDE that you can use to build and preview your site.
|
||||
- For a website, set `type: website`:
|
||||
|
||||
Read more at <https://bookdown.org/yihui/rmarkdown/rmarkdown-site.html>.
|
||||
``` yaml
|
||||
project:
|
||||
type: website
|
||||
```
|
||||
|
||||
For example, the following `_quarto.yml` file creates a website from three source files: `index.qmd` (the home page), `viridis-colors.qmd`, and `terrain-colors.qmd`.
|
||||
|
||||
```{r}
|
||||
#| echo: false
|
||||
#| comment: ""
|
||||
|
||||
cat(readr::read_file("quarto/example-site.yml"))
|
||||
```
|
||||
|
||||
The `_quarto.yml` file you need for a book is very similarly structured.
|
||||
The following example shows how you can create a book with four chapters that renders to three different outputs (`html`, `pdf`, and `epub`).
|
||||
Once again, the source files are `.qmd` files.
|
||||
|
||||
```{r}
|
||||
#| echo: false
|
||||
#| comment: ""
|
||||
|
||||
cat(readr::read_file("quarto/example-book.yml"))
|
||||
```
|
||||
|
||||
We recommend that you use an RStudio project for your websites and books.
|
||||
Based on the `_quarto.yml` file, RStudio will recognize the type of project you're working on, and add a Built tab to the IDE that you can use to render and preview your websites and books.
|
||||
Both websites and books can also be rendered using `quarto::render()`.
|
||||
|
||||
Read more at <https://quarto.org/docs/websites> about Quarto websites and <https://quarto.org/docs/books> about books.
|
||||
|
||||
## Other formats
|
||||
|
||||
Other packages provide even more output formats:
|
||||
Quarto offers even more output formats:
|
||||
|
||||
- The **bookdown** package, <https://pkgs.rstudio.com/bookdown>, makes it easy to write books, like this one.
|
||||
To learn more, read [*Authoring Books with R Markdown*](https://bookdown.org/yihui/bookdown/), by Yihui Xie, which is, of course, written in bookdown.
|
||||
Visit <https://www.bookdown.org> to see other bookdown books written by the wider R community.
|
||||
- You can write journal articles using Quarto Journal Templates: <https://quarto.org/docs/journals/templates.html>.
|
||||
|
||||
- The **prettydoc** package, [https://prettydoc.statr.me](https://prettydoc.statr.me/){.uri}, provides lightweight document formats with a range of attractive themes.
|
||||
- You can output Quarto documents to Jupyter Notebooks with `format: ipynb`: <https://quarto.org/docs/reference/formats/ipynb.html>.
|
||||
|
||||
- The **rticles** package, <https://pkgs.rstudio.com/rticles>, compiles a selection of formats tailored for specific scientific journals.
|
||||
|
||||
See <https://rmarkdown.rstudio.com/formats.html> for a list of even more formats.
|
||||
You can also create your own by following the instructions at <https://rmarkdown.rstudio.com/developer_custom_formats.html>.
|
||||
See <https://quarto.org/docs/output-formats/all-formats.html> for a list of even more formats.
|
||||
|
||||
## Learning more
|
||||
|
||||
|
|
|
@ -4,15 +4,15 @@
|
|||
#| results: "asis"
|
||||
#| echo: false
|
||||
source("_common.R")
|
||||
status("drafting")
|
||||
status("polishing")
|
||||
```
|
||||
|
||||
Earlier, we discussed a basic workflow for capturing your R code where you work interactively in the *console*, then capture what works in the *script editor*.
|
||||
R Markdown brings together the console and the script editor, blurring the lines between interactive exploration and long-term code capture.
|
||||
Quarto brings together the console and the script editor, blurring the lines between interactive exploration and long-term code capture.
|
||||
You can rapidly iterate within a chunk, editing and re-executing with Cmd/Ctrl + Shift + Enter.
|
||||
When you're happy, you move on and start a new chunk.
|
||||
|
||||
R Markdown is also important because it so tightly integrates prose and code.
|
||||
Quarto is also important because it so tightly integrates prose and code.
|
||||
This makes it a great **analysis notebook** because it lets you develop code and record your thoughts.
|
||||
An analysis notebook shares many of the same goals as a classic lab notebook in the physical sciences.
|
||||
It:
|
||||
|
@ -32,7 +32,7 @@ It:
|
|||
Much of the good advice about using lab notebooks effectively can also be translated to analysis notebooks.
|
||||
We've drawn on our own experiences and Colin Purrington's advice on lab notebooks (<https://colinpurrington.com/tips/lab-notebooks>) to come up with the following tips:
|
||||
|
||||
- Ensure each notebook has a descriptive title, an evocative filename, and a first paragraph that briefly describes the aims of the analysis.
|
||||
- Ensure each notebook has a descriptive title, an evocative file name, and a first paragraph that briefly describes the aims of the analysis.
|
||||
|
||||
- Use the YAML header date field to record the date you started working on the notebook:
|
||||
|
||||
|
@ -53,7 +53,8 @@ We've drawn on our own experiences and Colin Purrington's advice on lab notebook
|
|||
- If you discover an error in a data file, never modify it directly, but instead write code to correct the value.
|
||||
Explain why you made the fix.
|
||||
|
||||
- Before you finish for the day, make sure you can knit the notebook (if you're using caching, make sure to clear the caches).
|
||||
- Before you finish for the day, make sure you can render the notebook.
|
||||
If you're using caching, make sure to clear the caches.
|
||||
That will let you fix any problems while the code is still fresh in your mind.
|
||||
|
||||
- If you want your code to be reproducible in the long-run (i.e. so you can come back to run it next month or next year), you'll need to track the versions of the packages that your code uses.
|
||||
|
@ -61,5 +62,5 @@ We've drawn on our own experiences and Colin Purrington's advice on lab notebook
|
|||
A quick and dirty hack is to include a chunk that runs `sessionInfo()` --- that won't let you easily recreate your packages as they are today, but at least you'll know what they were.
|
||||
|
||||
- You are going to create many, many, many analysis notebooks over the course of your career.
|
||||
How are you going to organise them so you can find them again in the future?
|
||||
How are you going to organize them so you can find them again in the future?
|
||||
We recommend storing them in individual projects, and coming up with a good naming scheme.
|
|
@ -742,12 +742,12 @@ A good place to find CSL style files for common bibliography styles is <https://
|
|||
Quarto is still relatively young, and is still growing rapidly.
|
||||
The best place to stay on top of innovations is the official Quarto website: [https://quarto.org](https://quarto.org/){.uri}.
|
||||
|
||||
There are two important topics that we haven't covered here: collaboration, and the details of accurately communicating your ideas to other humans.
|
||||
There are two important topics that we haven't covered here: collaboration and the details of accurately communicating your ideas to other humans.
|
||||
Collaboration is a vital part of modern data science, and you can make your life much easier by using version control tools, like Git and GitHub.
|
||||
We recommend "Happy Git with R", a user friendly introduction to Git and GitHub from R users, by Jenny Bryan.
|
||||
The book is freely available online: <https://happygitwithr.com>
|
||||
The book is freely available online: <https://happygitwithr.com>.
|
||||
|
||||
We have not touched on what you should actually write in order to clearly communicate the results of your analysis.
|
||||
We have also not touched on what you should actually write in order to clearly communicate the results of your analysis.
|
||||
To improve your writing, we highly recommend reading either [*Style: Lessons in Clarity and Grace*](https://www.amazon.com/Style-Lessons-Clarity-Grace-12th/dp/0134080416) by Joseph M. Williams & Joseph Bizup, or [*The Sense of Structure: Writing from the Reader's Perspective*](https://www.amazon.com/Sense-Structure-Writing-Readers-Perspective/dp/0205296327) by George Gopen.
|
||||
Both books will help you understand the structure of sentences and paragraphs, and give you the tools to make your writing more clear.
|
||||
(These books are rather expensive if purchased new, but they're used by many English classes so there are plenty of cheap second-hand copies).
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
---
|
||||
title: "Diamonds distribution dashboard"
|
||||
output: flexdashboard::flex_dashboard
|
||||
---
|
||||
|
||||
```{r setup, include = FALSE}
|
||||
library(ggplot2)
|
||||
library(dplyr)
|
||||
knitr::opts_chunk$set(fig.width = 5, fig.asp = 1/3)
|
||||
```
|
||||
|
||||
## Column 1
|
||||
|
||||
### Carat
|
||||
|
||||
```{r}
|
||||
ggplot(diamonds, aes(carat)) + geom_histogram(binwidth = 0.1)
|
||||
```
|
||||
|
||||
### Cut
|
||||
|
||||
```{r}
|
||||
ggplot(diamonds, aes(cut)) + geom_bar()
|
||||
```
|
||||
|
||||
### Colour
|
||||
|
||||
```{r}
|
||||
ggplot(diamonds, aes(color)) + geom_bar()
|
||||
```
|
||||
|
||||
## Column 2
|
||||
|
||||
### The largest diamonds
|
||||
|
||||
```{r}
|
||||
diamonds |>
|
||||
arrange(desc(carat)) |>
|
||||
head(100) |>
|
||||
select(carat, cut, color, price) |>
|
||||
DT::datatable()
|
||||
```
|
|
@ -0,0 +1,17 @@
|
|||
project:
|
||||
type: book
|
||||
|
||||
book:
|
||||
title: "A book on color scales"
|
||||
author: "Jane Coloriste"
|
||||
chapters:
|
||||
- index.qmd
|
||||
- intro.qmd
|
||||
- viridis-colors.qmd
|
||||
- terrain-colors.qmd
|
||||
|
||||
format:
|
||||
html:
|
||||
theme: cosmo
|
||||
pdf: default
|
||||
epub: default
|
|
@ -1,10 +1,13 @@
|
|||
name: "my-website"
|
||||
navbar:
|
||||
title: "My Website"
|
||||
project:
|
||||
type: website
|
||||
|
||||
website:
|
||||
title: "A website on color scales"
|
||||
navbar:
|
||||
left:
|
||||
- text: "Home"
|
||||
href: index.html
|
||||
- text: "Viridis Colors"
|
||||
href: 1-example.html
|
||||
- text: "Terrain Colors"
|
||||
href: 3-inline.html
|
||||
- href: index.qmd
|
||||
text: Home
|
||||
- href: viridis-colors.qmd
|
||||
text: Viridis colors
|
||||
- href: terrain-colors.qmd
|
||||
text: Terrain colors
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 335 KiB |
|
@ -0,0 +1,63 @@
|
|||
---
|
||||
title: "💍 Diamonds dashboard"
|
||||
format: html
|
||||
execute:
|
||||
echo: false
|
||||
---
|
||||
|
||||
```{r}
|
||||
#| label: setup
|
||||
#| include: false
|
||||
|
||||
library(tidyverse)
|
||||
library(gt)
|
||||
```
|
||||
|
||||
::: panel-tabset
|
||||
## Plots
|
||||
|
||||
```{r}
|
||||
#| layout: [[30,-5, 30, -5, 30], [100]]
|
||||
|
||||
ggplot(diamonds, aes(x = carat)) + geom_histogram(binwidth = 0.1)
|
||||
ggplot(diamonds, aes(x = price)) + geom_histogram(binwidth = 500)
|
||||
ggplot(diamonds, aes(x = cut, color = cut)) + geom_bar()
|
||||
|
||||
ggplot(diamonds, aes(x = carat, y = price, color = cut)) + geom_point()
|
||||
```
|
||||
|
||||
## Summaries
|
||||
|
||||
```{r}
|
||||
diamonds |>
|
||||
select(price, carat, cut) |>
|
||||
group_by(cut) |>
|
||||
summarize(
|
||||
across(where(is.numeric), list(mean = mean, median = median, sd = sd, IQR = IQR))
|
||||
) |>
|
||||
pivot_longer(cols = -cut) |>
|
||||
pivot_wider(names_from = cut, values_from = value) |>
|
||||
separate(name, into = c("var", "stat")) |>
|
||||
mutate(
|
||||
var = str_to_title(var),
|
||||
stat = str_to_title(stat),
|
||||
stat = if_else(stat == "Iqr", "IQR", stat)
|
||||
) |>
|
||||
group_by(var) |>
|
||||
gt() |>
|
||||
fmt_currency(columns = -stat, rows = 1:4, decimals = 0) |>
|
||||
fmt_number(columns = -stat, rows = 5:8,) |>
|
||||
cols_align(columns = -stat, align = "center") |>
|
||||
cols_label(stat = "")
|
||||
```
|
||||
|
||||
## Data
|
||||
|
||||
```{r}
|
||||
diamonds |>
|
||||
arrange(desc(carat)) |>
|
||||
slice_head(n = 100) |>
|
||||
select(price, carat, cut) |>
|
||||
DT::datatable()
|
||||
```
|
||||
:::
|
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
format: html
|
||||
server: shiny
|
||||
---
|
||||
|
||||
```{r}
|
||||
library(shiny)
|
||||
|
||||
textInput("name", "What is your name?")
|
||||
numericInput("age", "How old are you?", NA, min = 0, max = 150)
|
||||
```
|
||||
|
||||
```{r}
|
||||
#| context: server
|
||||
```
|
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 115 KiB |
Binary file not shown.
Before Width: | Height: | Size: 43 KiB |
Binary file not shown.
Before Width: | Height: | Size: 18 KiB |
Loading…
Reference in New Issue