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
Copy file name to clipboardExpand all lines: viz.Rmd
+20-17Lines changed: 20 additions & 17 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 tool
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
@@ -186,7 +186,9 @@ understand and remember your message quickly.
186
186
#### *Build the visualization iteratively* {-}
187
187
188
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.
189
+
and then how to create the visualization in R \index{ggplot} using the `ggplot2` R package.
190
+
Given that the `ggplot2`package is one of the packages installed
191
+
and loaded by the `tidyverse` metapackage, we still only need to load that one package:
190
192
191
193
```{r 03-tidyverse, warning=FALSE, message=FALSE}
192
194
library(tidyverse)
@@ -479,7 +481,8 @@ labels and make the font more readable:
479
481
```{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
482
faithful_scatter <- ggplot(faithful, aes(x = waiting, y = eruptions)) +
481
483
geom_point() +
482
-
labs(x = "Waiting Time (mins)", y = "Eruption Duration (mins)") +
484
+
xlab("Waiting Time (mins)") +
485
+
ylab("Eruption Duration (mins)") +
483
486
theme(text = element_text(size = 12))
484
487
485
488
faithful_scatter
@@ -529,8 +532,8 @@ improve readability.
529
532
```{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
533
ggplot(can_lang, aes(x = most_at_home, y = mother_tongue)) +
531
534
geom_point() +
532
-
labs(x = "Language spoken most at home \n (number of Canadian residents)",
533
-
y = "Mother tongue \n (number of Canadian residents)") +
535
+
xlab("Language spoken most at home \n (number of Canadian residents)") +
536
+
ylab("Mother tongue \n (number of Canadian residents)") +
534
537
theme(text = element_text(size = 12))
535
538
```
536
539
@@ -596,8 +599,8 @@ library(scales)
596
599
597
600
ggplot(can_lang, aes(x = most_at_home, y = mother_tongue)) +
598
601
geom_point() +
599
-
labs(x = "Language spoken most at home \n (number of Canadian residents)",
600
-
y = "Mother tongue \n (number of Canadian residents)") +
602
+
xlab("Language spoken most at home \n (number of Canadian residents)") +
603
+
ylab("Mother tongue \n (number of Canadian residents)") +
601
604
theme(text = element_text(size = 12)) +
602
605
scale_x_log10(labels = label_comma()) +
603
606
scale_y_log10(labels = label_comma())
@@ -651,8 +654,8 @@ the final result.
651
654
```{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
655
ggplot(can_lang, aes(x = most_at_home_percent, y = mother_tongue_percent)) +
653
656
geom_point() +
654
-
labs(x = "Language spoken most at home \n (percentage of Canadian residents)",
655
-
y = "Mother tongue \n (percentage of Canadian residents)") +
657
+
xlab("Language spoken most at home \n (percentage of Canadian residents)") +
658
+
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)") +
789
+
xlab("Language spoken most at home \n (percentage of Canadian residents)") +
790
+
ylab("Mother tongue \n (percentage of Canadian residents)") +
788
791
theme(text = element_text(size = 12),
789
792
legend.position = "top",
790
793
legend.direction = "vertical") +
@@ -1087,7 +1090,7 @@ instead of stacked bars
1087
1090
(which is the default for bar plots or histograms
1088
1091
when they are colored by another categorical variable).
1089
1092
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."}
1093
+
```{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
1094
morley_hist <- ggplot(morley, aes(x = Speed, fill = Expt)) +
1092
1095
geom_histogram(alpha = 0.5, position = "identity") +
0 commit comments