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=3, warning=FALSE, fig.cap = "Bar plot of the ten Aboriginal languages most often reported by Canadian residents as their mother tongue. Note that this visualization is not done yet; there are still improvements to be made."}
531
+
```{r barplot-mother-tongue, fig.width=5, fig.height=3.1, warning=FALSE, fig.cap = "Bar plot of the ten Aboriginal languages most often reported by Canadian residents as their mother tongue. Note that this visualization is not done yet; there are still improvements to be made."}
532
532
ggplot(ten_lang, aes(x = language, y = mother_tongue)) +
Copy file name to clipboardExpand all lines: viz.Rmd
+22-18Lines changed: 22 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -143,7 +143,7 @@ alternative.
143
143
## Refining the visualization
144
144
#### *Convey the message, minimize noise* {-}
145
145
146
-
Just being able to make a visualization in R with `ggplot2`(or any other tool
146
+
Just being able to make a visualization in R (or any other language,
147
147
for that matter) doesn't mean that it effectively communicates your message to
148
148
others. Once you have selected a broad type of visualization to use, you will
149
149
have to refine it to suit your particular need. Some rules of thumb for doing
@@ -185,8 +185,11 @@ understand and remember your message quickly.
185
185
## Creating visualizations with `ggplot2`
186
186
#### *Build the visualization iteratively* {-}
187
187
188
-
This section will cover examples of how to choose and refine a visualization given a data set and a question that you want to answer,
189
-
and then how to create the visualization in R \index{ggplot} using `ggplot2`. To use the `ggplot2` package, we need to load the `tidyverse` metapackage.
188
+
This section will cover examples of how to choose and refine a visualization
189
+
given a data set and a question that you want to answer, and then how to create
190
+
the visualization in R \index{ggplot} using the `ggplot2` R package. Given that
191
+
the `ggplot2`package is loaded by the `tidyverse` metapackage, we still
192
+
need to load only `tidyverse':
190
193
191
194
```{r 03-tidyverse, warning=FALSE, message=FALSE}
192
195
library(tidyverse)
@@ -479,7 +482,8 @@ labels and make the font more readable:
479
482
```{r 03-data-faithful-scatter-2, warning=FALSE, message=FALSE, fig.height = 3.5, fig.width = 3.75, fig.align = "center", fig.pos = "H", out.extra="", fig.cap = "Scatter plot of waiting time and eruption time with clearer axes and labels."}
480
483
faithful_scatter <- ggplot(faithful, aes(x = waiting, y = eruptions)) +
481
484
geom_point() +
482
-
labs(x = "Waiting Time (mins)", y = "Eruption Duration (mins)") +
485
+
xlab("Waiting Time (mins)") +
486
+
ylab("Eruption Duration (mins)") +
483
487
theme(text = element_text(size = 12))
484
488
485
489
faithful_scatter
@@ -529,8 +533,8 @@ improve readability.
529
533
```{r 03-mother-tongue-vs-most-at-home-labs, fig.height=3.5, fig.width=3.75, fig.align = "center", warning=FALSE, fig.pos = "H", out.extra="", fig.cap = "Scatter plot of number of Canadians reporting a language as their mother tongue vs the primary language at home with x and y labels."}
530
534
ggplot(can_lang, aes(x = most_at_home, y = mother_tongue)) +
531
535
geom_point() +
532
-
labs(x = "Language spoken most at home \n (number of Canadian residents)",
533
-
y = "Mother tongue \n (number of Canadian residents)") +
536
+
xlab("Language spoken most at home \n (number of Canadian residents)") +
537
+
ylab("Mother tongue \n (number of Canadian residents)") +
534
538
theme(text = element_text(size = 12))
535
539
```
536
540
@@ -596,8 +600,8 @@ library(scales)
596
600
597
601
ggplot(can_lang, aes(x = most_at_home, y = mother_tongue)) +
598
602
geom_point() +
599
-
labs(x = "Language spoken most at home \n (number of Canadian residents)",
600
-
y = "Mother tongue \n (number of Canadian residents)") +
603
+
xlab("Language spoken most at home \n (number of Canadian residents)") +
604
+
ylab("Mother tongue \n (number of Canadian residents)") +
601
605
theme(text = element_text(size = 12)) +
602
606
scale_x_log10(labels = label_comma()) +
603
607
scale_y_log10(labels = label_comma())
@@ -651,8 +655,8 @@ the final result.
651
655
```{r 03-mother-tongue-vs-most-at-home-scale-props, fig.height=3.5, fig.width=3.75, fig.align = "center", warning=FALSE, fig.pos = "H", out.extra="", fig.cap = "Scatter plot of percentage of Canadians reporting a language as their mother tongue vs the primary language at home."}
652
656
ggplot(can_lang, aes(x = most_at_home_percent, y = mother_tongue_percent)) +
653
657
geom_point() +
654
-
labs(x = "Language spoken most at home \n (percentage of Canadian residents)",
655
-
y = "Mother tongue \n (percentage of Canadian residents)") +
658
+
xlab("Language spoken most at home \n (percentage of Canadian residents)") +
659
+
ylab("Mother tongue \n (percentage of Canadian residents)") +
labs(x = "Language spoken most at home \n (percentage of Canadian residents)",
787
-
y = "Mother tongue \n (percentage of Canadian residents)") +
790
+
xlab("Language spoken most at home \n (percentage of Canadian residents)") +
791
+
ylab("Mother tongue \n (percentage of Canadian residents)") +
788
792
theme(text = element_text(size = 12),
789
793
legend.position = "top",
790
794
legend.direction = "vertical") +
@@ -1087,7 +1091,7 @@ instead of stacked bars
1087
1091
(which is the default for bar plots or histograms
1088
1092
when they are colored by another categorical variable).
1089
1093
1090
-
```{r 03-data-morley-hist-3, warning=FALSE, message=FALSE, fig.height = 2.75, fig.width = 4.5, fig.align = "center", fig.pos = "H", out.extra="", fig.cap = "Histogram of Michelson's speed of light data colored by experiment."}
1094
+
```{r 03-data-morley-hist-3, warning=FALSE, message=FALSE, fig.height = 2.75, fig.width = 4.5, fig.align = "center", fig.pos = "H", out.extra="", fig.cap = "Histogram of Michelson's speed of light data where an attempt is made to color the bars by experiment."}
1091
1095
morley_hist <- ggplot(morley, aes(x = Speed, fill = Expt)) +
1092
1096
geom_histogram(alpha = 0.5, position = "identity") +
0 commit comments