Skip to content

Commit 6b907ca

Browse files
committed
chapter 1 - added fixed figures where needed without creating awkward large whitespaces
1 parent 4adcecf commit 6b907ca

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

intro.Rmd

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ to read data into R.
260260

261261
(ref:img-read-csv) Syntax for the `read_csv` function.
262262

263-
``` {r img-read-csv, echo = FALSE, message = FALSE, warning = FALSE, fig.cap = "(ref:img-read-csv)", fig.retina = 2, out.width="100%"}
263+
``` {r img-read-csv, echo = FALSE, message = FALSE, warning = FALSE, fig.cap = "(ref:img-read-csv)", fig.retina = 2, out.width="100%", fig.pos = "H"}
264264
image_read("img/read_csv_function.jpeg") |>
265265
image_crop("1625x1900")
266266
```
@@ -528,7 +528,7 @@ image_read("img/ggplot_function.jpeg") |>
528528
image_crop("1625x1900")
529529
```
530530

531-
```{r barplot-mother-tongue, fig.width=5, fig.height=4, warning=FALSE, fig.cap = "Bar plot of the ten Aboriginal languages most often reported by Canadian residents as their mother tongue."}
531+
```{r barplot-mother-tongue, fig.width=5, fig.height=3, warning=FALSE, fig.cap = "Bar plot of the ten Aboriginal languages most often reported by Canadian residents as their mother tongue."}
532532
ggplot(ten_lang, aes(x = language, y = mother_tongue)) +
533533
geom_bar(stat = "identity")
534534
```
@@ -567,7 +567,9 @@ words (e.g. `"Mother Tongue (Number of Canadian Residents)"`) as arguments to
567567
layers to format the plot further, and we will explore these in Chapter
568568
\@ref(viz).
569569

570-
```{r barplot-mother-tongue-labs, fig.width=5, fig.height=4, warning=FALSE, fig.cap = "Bar plot of the ten Aboriginal languages most often reported by Canadian residents as their mother tongue with x and y labels."}
570+
(ref:barplot-mother-tongue-labs) Bar plot of the ten Aboriginal languages most often reported by Canadian residents as their mother tongue with x and y labels.
571+
572+
```{r barplot-mother-tongue-labs, fig.width=5, fig.height=3.6, warning=FALSE, fig.cap = "(ref:barplot-mother-tongue-labs)", fig.pos = "H", out.extra=""}
571573
ggplot(ten_lang, aes(x = language, y = mother_tongue)) +
572574
geom_bar(stat = "identity") +
573575
xlab("Language") +
@@ -581,7 +583,7 @@ currently making it difficult to read the different language names.
581583
One solution is to rotate the plot such that the bars are horizontal rather than vertical.
582584
To accomplish this, we will swap the x and y coordinate axes:
583585

584-
```{r barplot-mother-tongue-flipped, fig.width=5, fig.height=3, warning=FALSE, fig.cap = "Horizontal bar plot of the ten Aboriginal languages most often reported by Canadian residents as their mother tongue."}
586+
```{r barplot-mother-tongue-flipped, fig.width=5, fig.height=3, fig.pos = "H", warning=FALSE, fig.cap = "Horizontal bar plot of the ten Aboriginal languages most often reported by Canadian residents as their mother tongue."}
585587
ggplot(ten_lang, aes(x = mother_tongue, y = language)) +
586588
geom_bar(stat = "identity") +
587589
xlab("Mother Tongue (Number of Canadian Residents)") +
@@ -597,6 +599,8 @@ each language, rather than in alphabetical order. We can reorder the bars using
597599
the `reorder` \index{reorder} function, which orders a variable (here `language`) based on the
598600
values of the second variable (`mother_tongue`).
599601

602+
\newpage
603+
600604
```{r barplot-mother-tongue-reorder, fig.width=5, fig.height=3, warning=FALSE, fig.cap = "Bar plot of the ten Aboriginal languages most often reported by Canadian residents as their mother tongue with bars reordered."}
601605
ggplot(ten_lang, aes(x = mother_tongue,
602606
y = reorder(language, mother_tongue))) +
@@ -633,6 +637,14 @@ of code for others, and perhaps more importantly, your future self!
633637
It's good practice to get in the habit of
634638
commenting your code to improve its readability.
635639

640+
This exercise demonstrates the power of R. In relatively few lines of code, we
641+
performed an entire data science workflow with a highly effective data
642+
visualization! We asked a question, loaded the data into R, wrangled the data
643+
(using `filter`, `arrange` and `slice`) and created a data visualization to
644+
help answer our question. In this chapter, you got a quick taste of the data
645+
science workflow; continue on with the next few chapters to learn each of
646+
these steps in much more detail!
647+
636648
```{r nachos-to-cheesecake, fig.width=5, fig.height=3, warning=FALSE, message=FALSE, fig.cap = "Putting it all together: bar plot of the ten Aboriginal languages most often reported by Canadian residents as their mother tongue."}
637649
library(tidyverse)
638650
@@ -652,14 +664,6 @@ ggplot(ten_lang, aes(x = mother_tongue,
652664
ylab("Language")
653665
```
654666

655-
This exercise demonstrates the power of R. In relatively few lines of code, we
656-
performed an entire data science workflow with a highly effective data
657-
visualization! We asked a question, loaded the data into R, wrangled the data
658-
(using `filter`, `arrange` and `slice`) and created a data visualization to
659-
help answer our question. In this chapter, you got a quick taste of the data
660-
science workflow; continue on with the next few chapters to learn each of
661-
these steps in much more detail!
662-
663667
## Accessing documentation
664668

665669
There are many R functions in the `tidyverse` package (and beyond!), and

pdf/index.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ cover-image: img/chapter_overview.jpg
2323
---
2424

2525
```{r setup-pdf, include=FALSE}
26-
knitr::opts_chunk$set(fig.pos = "H",
27-
out.extra = "")
26+
#knitr::opts_chunk$set(fig.pos = "H",
27+
# out.extra = "")
2828
2929
```
3030

reading.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ knitr::opts_chunk$set(message = FALSE,
99
1010
print_html_nodes <- function(html_nodes_object) {
1111
if(!is_latex_output()) {
12-
html_nodes
12+
html_nodes_object
1313
} else {
1414
output <- capture.output(html_nodes_object)
1515

0 commit comments

Comments
 (0)