Skip to content

Commit 8d90bf9

Browse files
authored
Update dataviz-storytelling.md
1 parent a209b7b commit 8d90bf9

File tree

1 file changed

+2
-63
lines changed

1 file changed

+2
-63
lines changed

_tutorials/dataviz-storytelling.md

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ subtitle: Data visualisation meets graphic design to tell scientific stories
55
date: 2022-12-12 10:00:00
66
author: Gergana
77
redirect_from:
8-
- /2022/12/12/dataviz-beautification-synthesis.html
8+
- /2022/12/12/dataviz-storytelling.html
99
tags: data-vis intermediate advanced
1010
---
1111

@@ -520,68 +520,7 @@ ggsave(distributions6, filename = "distributions6.png",
520520

521521
<center> <img src="{{ site.baseurl }}/assets/img/tutorials/dataviz-beautification-synthesis/distributions6.png" alt="Img" style="width: 500px;"/> </center>
522522

523-
Final stop along this specific beautification journey, for now at least! But before we move onto histograms, a note about another useful `tidyverse` feature - being able to quickly create a new variable based on conditions from more than one of the existing variables.
524-
525-
<div class="bs-callout-blue" markdown="1">
526-
527-
__A data manipulation tip:__ Using `case_when()`, combined with `mutate`, is a great way to create new variables based on one or more conditions from other variables.
528-
</div>
529-
530-
```r
531-
# Create new columns based on a combo of conditions using case_when()
532-
# A fictional example
533-
alpine_magic <- niwot_richness %>% mutate(fairy_dust = case_when(fert == "PP" & hits > 5 ~ "Blue fairy dust",
534-
fert == "CC" & hits > 15 ~ "The ultimate fairy dust"))
535-
536-
(distributions_magic <-
537-
ggplot(data = alpine_magic,
538-
aes(x = reorder(fairy_dust, desc(richness)), y = richness, fill = fairy_dust)) +
539-
geom_flat_violin(position = position_nudge(x = 0.2, y = 0), alpha = 0.8) +
540-
geom_point(aes(y = richness, color = fairy_dust),
541-
position = position_jitter(width = 0.15), size = 1, alpha = 0.1) +
542-
geom_boxplot(width = 0.2, outlier.shape = NA, alpha = 0.8) +
543-
labs(y = "\nSpecies richness", x = NULL) +
544-
guides(fill = FALSE, color = FALSE) +
545-
scale_y_continuous(limits = c(0, 30)) +
546-
scale_fill_manual(values = c("turquoise4", "magenta4")) +
547-
scale_colour_manual(values = c("turquoise4", "magenta4")) +
548-
coord_flip() +
549-
theme_niwot())
550-
```
551-
552-
<center> <img src="{{ site.baseurl }}/assets/img/tutorials/dataviz-beautification-synthesis/distributions_magic1.png" alt="Img" style="width: 600px;"/> </center>
553-
554-
<div class="bs-callout-blue" markdown="1">
555-
556-
__A data manipulation tip:__ Often we have missing values, or not everything has a category, for example in the magic plot above, many of the species are classified as `NA`. If we want to drop those records, we can use `drop_na()` and in the brackets specify which specific column(s) should be the evaluator.
557-
</div>
558-
559-
```r
560-
alpine_magic_only <- alpine_magic %>% drop_na(fairy_dust)
561-
562-
(distributions_magic2 <-
563-
ggplot(data = alpine_magic_only,
564-
aes(x = reorder(fairy_dust, desc(richness)), y = richness, fill = fairy_dust)) +
565-
geom_flat_violin(position = position_nudge(x = 0.2, y = 0), alpha = 0.8) +
566-
geom_point(aes(y = richness, color = fairy_dust),
567-
position = position_jitter(width = 0.15), size = 1, alpha = 0.1) +
568-
geom_boxplot(width = 0.2, outlier.shape = NA, alpha = 0.8) +
569-
labs(y = "\nSpecies richness", x = NULL) +
570-
guides(fill = FALSE, color = FALSE) +
571-
scale_y_continuous(limits = c(0, 30)) +
572-
scale_fill_manual(values = c("turquoise4", "magenta4")) +
573-
scale_colour_manual(values = c("turquoise4", "magenta4")) +
574-
coord_flip() +
575-
theme_niwot())
576-
577-
ggsave(distributions_magic2, filename = "distributions_magic2.png",
578-
height = 5, width = 5)
579-
```
580-
581-
<center> <img src="{{ site.baseurl }}/assets/img/tutorials/dataviz-beautification-synthesis/distributions_magic2.png" alt="Img" style="width: 600px;"/> </center>
582-
583-
Raining or not, both versions of the raincloud plot look alright, so like many things in data viz, a matter of personal preferenece.
584-
523+
Final stop along this specific beautification journey, for now at least!
585524
<a name="distributions"></a>
586525

587526
## Make, customise and annotate histograms

0 commit comments

Comments
 (0)