You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
```{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."}
532
532
ggplot(ten_lang, aes(x = language, y = mother_tongue)) +
533
533
geom_bar(stat = "identity")
534
534
```
@@ -567,7 +567,9 @@ words (e.g. `"Mother Tongue (Number of Canadian Residents)"`) as arguments to
567
567
layers to format the plot further, and we will explore these in Chapter
568
568
\@ref(viz).
569
569
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.
ggplot(ten_lang, aes(x = language, y = mother_tongue)) +
572
574
geom_bar(stat = "identity") +
573
575
xlab("Language") +
@@ -581,7 +583,7 @@ currently making it difficult to read the different language names.
581
583
One solution is to rotate the plot such that the bars are horizontal rather than vertical.
582
584
To accomplish this, we will swap the x and y coordinate axes:
583
585
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."}
585
587
ggplot(ten_lang, aes(x = mother_tongue, y = language)) +
586
588
geom_bar(stat = "identity") +
587
589
xlab("Mother Tongue (Number of Canadian Residents)") +
@@ -597,6 +599,8 @@ each language, rather than in alphabetical order. We can reorder the bars using
597
599
the `reorder` \index{reorder} function, which orders a variable (here `language`) based on the
598
600
values of the second variable (`mother_tongue`).
599
601
602
+
\newpage
603
+
600
604
```{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."}
601
605
ggplot(ten_lang, aes(x = mother_tongue,
602
606
y = reorder(language, mother_tongue))) +
@@ -633,6 +637,14 @@ of code for others, and perhaps more importantly, your future self!
633
637
It's good practice to get in the habit of
634
638
commenting your code to improve its readability.
635
639
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
+
636
648
```{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."}
0 commit comments