Skip to content

Commit

Permalink
updated downloadable files, fixed typos
Browse files Browse the repository at this point in the history
  • Loading branch information
gwyssen committed Jan 31, 2024
1 parent c607733 commit ff27d5d
Show file tree
Hide file tree
Showing 8 changed files with 468 additions and 642 deletions.
37 changes: 19 additions & 18 deletions datavisualization.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ d <- read.csv("data/DatasaurusDozen.csv") |>
d_summary <- d |> group_by(condition) |>
summarise(mean_x = mean(x),
sd_x = sd(x),
mean_y = mean(y),
sd_y = sd(x))
mean_y = mean(y))
```

A graph contains always:

- **data**
- ***data***

- **geoms**, visible forms (*aesthetics*) such as points, lines or boxes.
- ***geoms***, visible forms (*aesthetics*) such as points, lines or boxes.

- **a coordinate systems / mapping** describes how data and geoms are linked, also colors or grouping variables are specified here
- ***a coordinate systems / mapping*** describes how data and geoms are linked, also colors or grouping variables are specified here

Further components could be:

Expand All @@ -42,25 +40,25 @@ Further components could be:

- coordinate functions

- **facets**
- ***facets***

- scales

- **themes**
- ***themes***

(we will only cover the contents in **bold**)
(we will only cover the contents in italics)

::: {.callout-tip appearance="simple"}
## Good to know

- It is easiest when your data is in *long* format.
- For plotting with `ggplot()` it is easiest when your data is in *long* format.

- What variables do you want to plot (categorical? continuous? ...)
- What variables do you want to plot (categorical? continuous? ...) affects which `geoms`can be used. You can try out what is suited with the `esquisse`-package below or find ideas [here](https://www.data-to-viz.com).
:::

## Data, geoms and mapping

We start with entering the current data frame and add geoms and mappings (`aes()`) with arguments such as
We start with entering the current data frame and add `geoms` and mappings (specified with `aes()`) with arguments such as

```{r}
ggplot(d_summary, # data
Expand All @@ -80,7 +78,7 @@ Examples of available geoms:
- boxplots: `geom_boxplot()`
- violin plots: `geom_violin()`

<aside>\[Here\]https://github.com/rstudio/cheatsheets/blob/main/data-visualization.pdf) you can download `ggplot`-Cheatsheet(</aside>
<aside>[Here](https://github.com/rstudio/cheatsheets/blob/main/data-visualization.pdf) you can download `ggplot`-Cheatsheet</aside>

## Facets

Expand All @@ -101,13 +99,14 @@ ggplot(data = d,
y = y)) +
geom_point() +
ggtitle ("Title") +
xlab("Value 1 [a.u.]") +
ylab("Value 2 [a.u.]") +
labs(title = "Title",
x = "Variable A [a.u.]",
y = "Variable B [a.u.]") +
theme_minimal() # also theme_classic and theme_minimal are nice
```

::: {.callout-tip appearance="simple"}
## \`esquisse\`-package
## `esquisse`-package

With this package you can use the data frames in your current environment or load a new one to try out which geoms might be useful

Expand All @@ -120,9 +119,11 @@ esquisse::esquisser()
```
:::

<aside>If we do not want to load the whole library we can call the function by writing the library name then `::` and the function afterwards such as `esquisse::esquisser()`. This is helpful when libraries have overlapping function names which can create conflicts or to easily call a function without typing `library()` first.</aside>

Further helpful ressources:

- [`ggplot`documentation](https://ggplot2.tidyverse.org/)
- [`ggplot2`documentation](https://ggplot2.tidyverse.org/)

- [Website PsyTeachR: Data Skills for reproducible research](https://psyteachr.github.io/reprores-v3)

Expand All @@ -132,4 +133,4 @@ Further helpful ressources:

- [Here](https://www.data-to-viz.com) you find ideas for plots.

- https://rstudio-connect.psy.gla.ac.uk/plotdemo/
- [Demo of different geoms](https://rstudio-connect.psy.gla.ac.uk/plotdemo)
2 changes: 1 addition & 1 deletion datawrangling.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Data visualization and analysis is often easier in this format. If your data is

- each measurement has one column

- each entity (e.g. person) has one column
- each entity (e.g. person) has one row

This data format makes it easy to spot missing values or outliers and count how many observations you have.

Expand Down
42 changes: 22 additions & 20 deletions docs/datavisualization.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,26 +238,24 @@ <h2 data-number="4.1" class="anchored" data-anchor-id="creating-graphs-with-ggpl
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a>d_summary <span class="ot">&lt;-</span> d <span class="sc">|&gt;</span> <span class="fu">group_by</span>(condition) <span class="sc">|&gt;</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarise</span>(<span class="at">mean_x =</span> <span class="fu">mean</span>(x),</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> <span class="at">sd_x =</span> <span class="fu">sd</span>(x),</span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> <span class="at">mean_y =</span> <span class="fu">mean</span>(y),</span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a> <span class="at">sd_y =</span> <span class="fu">sd</span>(x))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> <span class="at">mean_y =</span> <span class="fu">mean</span>(y))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>A graph contains always:</p>
<ul>
<li><p><strong>data</strong></p></li>
<li><p><strong>geoms</strong>, visible forms (<em>aesthetics</em>) such as points, lines or boxes.</p></li>
<li><p><strong>a coordinate systems / mapping</strong> describes how data and geoms are linked, also colors or grouping variables are specified here</p></li>
<li><p><strong><em>data</em></strong></p></li>
<li><p><strong><em>geoms</em></strong>, visible forms (<em>aesthetics</em>) such as points, lines or boxes.</p></li>
<li><p><strong><em>a coordinate systems / mapping</em></strong> describes how data and geoms are linked, also colors or grouping variables are specified here</p></li>
</ul>
<p>Further components could be:</p>
<ul>
<li><p>statistical parameters</p></li>
<li><p>positions</p></li>
<li><p>coordinate functions</p></li>
<li><p><strong>facets</strong></p></li>
<li><p><strong><em>facets</em></strong></p></li>
<li><p>scales</p></li>
<li><p><strong>themes</strong></p></li>
<li><p><strong><em>themes</em></strong></p></li>
</ul>
<p>(we will only cover the contents in <strong>bold</strong>)</p>
<p>(we will only cover the contents in italics)</p>
<div class="callout callout-style-simple callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
Expand All @@ -269,15 +267,15 @@ <h2 data-number="4.1" class="anchored" data-anchor-id="creating-graphs-with-ggpl
</div>
<div class="callout-body-container callout-body">
<ul>
<li><p>It is easiest when your data is in <em>long</em> format.</p></li>
<li><p>What variables do you want to plot (categorical? continuous? …)</p></li>
<li><p>For plotting with <code>ggplot()</code> it is easiest when your data is in <em>long</em> format.</p></li>
<li><p>What variables do you want to plot (categorical? continuous? …) affects which <code>geoms</code>can be used. You can try out what is suited with the <code>esquisse</code>-package below or find ideas <a href="https://www.data-to-viz.com">here</a>.</p></li>
</ul>
</div>
</div>
</section>
<section id="data-geoms-and-mapping" class="level2 page-columns page-full" data-number="4.2">
<h2 data-number="4.2" class="anchored" data-anchor-id="data-geoms-and-mapping"><span class="header-section-number">4.2</span> Data, geoms and mapping</h2>
<p>We start with entering the current data frame and add geoms and mappings (<code>aes()</code>) with arguments such as</p>
<p>We start with entering the current data frame and add <code>geoms</code> and mappings (specified with <code>aes()</code>) with arguments such as</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(d_summary, <span class="co"># data</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">aes</span>(<span class="at">x =</span> mean_x, <span class="at">y =</span> mean_y)) <span class="sc">+</span> <span class="co"># mapping</span></span>
Expand All @@ -298,7 +296,7 @@ <h2 data-number="4.2" class="anchored" data-anchor-id="data-geoms-and-mapping"><
<li>violin plots: <code>geom_violin()</code></li>
</ul>
<aside>
[Here]https://github.com/rstudio/cheatsheets/blob/main/data-visualization.pdf) you can download <code>ggplot</code>-Cheatsheet(
<a href="https://github.com/rstudio/cheatsheets/blob/main/data-visualization.pdf">Here</a> you can download <code>ggplot</code>-Cheatsheet
</aside>
</section>
<section id="facets" class="level2" data-number="4.3">
Expand All @@ -314,17 +312,18 @@ <h2 data-number="4.3" class="anchored" data-anchor-id="facets"><span class="head
</div>
</div>
</section>
<section id="themes-and-labels" class="level2" data-number="4.4">
<section id="themes-and-labels" class="level2 page-columns page-full" data-number="4.4">
<h2 data-number="4.4" class="anchored" data-anchor-id="themes-and-labels"><span class="header-section-number">4.4</span> Themes and labels</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(<span class="at">data =</span> d,</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="at">mapping =</span> <span class="fu">aes</span>(<span class="at">x =</span> x,</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="at">y =</span> y)) <span class="sc">+</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggtitle</span> (<span class="st">"Title"</span>) <span class="sc">+</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">xlab</span>(<span class="st">"Value 1 [a.u.]"</span>) <span class="sc">+</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">ylab</span>(<span class="st">"Value 2 [a.u.]"</span>) <span class="sc">+</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_minimal</span>() <span class="co"># also theme_classic and theme_minimal are nice</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Title"</span>, </span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="st">"Variable A [a.u.]"</span>,</span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> <span class="at">y =</span> <span class="st">"Variable B [a.u.]"</span>) <span class="sc">+</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_minimal</span>() <span class="co"># also theme_classic and theme_minimal are nice</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="datavisualization_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid" width="672"></p>
</div>
Expand All @@ -335,7 +334,7 @@ <h2 data-number="4.4" class="anchored" data-anchor-id="themes-and-labels"><span
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
`esquisse`-package
<code>esquisse</code>-package
</div>
</div>
<div class="callout-body-container callout-body">
Expand All @@ -347,14 +346,17 @@ <h2 data-number="4.4" class="anchored" data-anchor-id="themes-and-labels"><span
</div>
</div>
</div>
<aside>
If we do not want to load the whole library we can call the function by writing the library name then <code>::</code> and the function afterwards such as <code>esquisse::esquisser()</code>. This is helpful when libraries have overlapping function names which can create conflicts or to easily call a function without typing <code>library()</code> first.
</aside>
<p>Further helpful ressources:</p>
<ul>
<li><p><a href="https://ggplot2.tidyverse.org/"><code>ggplot</code>documentation</a></p></li>
<li><p><a href="https://ggplot2.tidyverse.org/"><code>ggplot2</code>documentation</a></p></li>
<li><p><a href="https://psyteachr.github.io/reprores-v3">Website PsyTeachR: Data Skills for reproducible research</a></p></li>
<li><p><a href="https://youtu.be/90IdULVGmYY">Start of the PsyTeachR videos by Lisa DeBruine</a>, e.g.&nbsp;<a href="https://youtu.be/tOFQFPRgZ3M">Basic Plots</a>, <a href="https://youtu.be/kKlQupjD__g">Common Plots</a> and <a href="https://youtu.be/6pHuCbOh86s">Plot Themes and Customization</a></p></li>
<li><p><a href="https://methodenlehre.github.io/einfuehrung-in-R/chapters/05-plotting.html">Einführung in R</a> by Andrew Ellis and Boris</p></li>
<li><p><a href="https://www.data-to-viz.com">Here</a> you find ideas for plots.</p></li>
<li><p>https://rstudio-connect.psy.gla.ac.uk/plotdemo/</p></li>
<li><p><a href="https://rstudio-connect.psy.gla.ac.uk/plotdemo">Demo of different geoms</a></p></li>
</ul>


Expand Down
Binary file modified docs/datavisualization_files/figure-html/unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/datawrangling.html
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ <h2 data-number="3.2" class="anchored" data-anchor-id="change-the-data-format-fr
<p><strong><em>Wide format</em></strong></p>
<ul>
<li><p>each measurement has one column</p></li>
<li><p>each entity (e.g.&nbsp;person) has one column</p></li>
<li><p>each entity (e.g.&nbsp;person) has one row</p></li>
</ul>
<p>This data format makes it easy to spot missing values or outliers and count how many observations you have.</p>
<hr>
Expand Down
Loading

0 comments on commit ff27d5d

Please sign in to comment.