Skip to content

Commit 341e49d

Browse files
committed
changing figure sizes of canadian plots back to original, changing line plot fig size and ggplot function image crop
1 parent 20cda7a commit 341e49d

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

viz.Rmd

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ library(tidyverse)
55
library(cowplot)
66
library(knitr)
77
library(kableExtra)
8+
library(magick)
9+
810
911
knitr::opts_chunk$set(fig.align = "center")
1012
```
@@ -289,10 +291,11 @@ default settings.
289291
(ref:03-ggplot-function-scatter) Creating a scatter plot with the `ggplot` function.
290292

291293
```{r 03-ggplot-function-scatter, echo = FALSE, fig.cap = "(ref:03-ggplot-function-scatter)", message = FALSE, out.width = "100%"}
292-
knitr::include_graphics("img/ggplot_function_scatter.jpeg")
294+
image_read("img/ggplot_function_scatter.jpeg") |>
295+
image_crop("1625x1900")
293296
```
294297

295-
```{r 03-data-co2-scatter, warning=FALSE, message=FALSE, fig.height = 3.5, fig.width = 3.75, fig.align = "center", fig.cap = "Scatter plot of atmospheric concentration of CO$_{2}$ over time."}
298+
```{r 03-data-co2-scatter, warning=FALSE, message=FALSE, fig.height = 3.5, fig.width = 4.5, fig.align = "center", fig.cap = "Scatter plot of atmospheric concentration of CO$_{2}$ over time."}
296299
co2_scatter <- ggplot(co2_df, aes(x = date_measured, y = ppm)) +
297300
geom_point()
298301
@@ -323,7 +326,7 @@ Let's now try to visualize the `co2_df` as a line plot
323326
with just the default arguments:
324327
\index{ggplot!geom\_line}
325328

326-
```{r 03-data-co2-line, warning=FALSE, message=FALSE, fig.height = 3.5, fig.width = 3.75, fig.align = "center", fig.cap = "Line plot of atmospheric concentration of CO$_{2}$ over time."}
329+
```{r 03-data-co2-line, warning=FALSE, message=FALSE, fig.height = 3.5, fig.width = 4.5, fig.align = "center", fig.cap = "Line plot of atmospheric concentration of CO$_{2}$ over time."}
327330
co2_line <- ggplot(co2_df, aes(x = date_measured, y = ppm)) +
328331
geom_line()
329332
@@ -355,7 +358,7 @@ change the font size, we use the `theme` function with the `text` argument:
355358
> Interested readers may consult the `theme` function documentation;
356359
> see the additional resources section at the end of this chapter.
357360
358-
```{r 03-data-co2-line-2, warning=FALSE, message=FALSE, fig.height = 3.5, fig.width = 3.75, fig.align = "center", fig.cap = "Line plot of atmospheric concentration of CO$_{2}$ over time with clearer axes and labels."}
361+
```{r 03-data-co2-line-2, warning=FALSE, message=FALSE, fig.height = 3.5, fig.width = 4.5, fig.align = "center", fig.cap = "Line plot of atmospheric concentration of CO$_{2}$ over time with clearer axes and labels."}
359362
co2_line <- ggplot(co2_df, aes(x = date_measured, y = ppm)) +
360363
geom_line() +
361364
xlab("Year") +
@@ -388,7 +391,7 @@ to convert the character strings we provide to `c` to `date` vectors.
388391
> but is not loaded by it.
389392
> Hence we need to load it separately in the code below.
390393
391-
```{r 03-data-co2-line-3, warning = FALSE, message = FALSE, fig.height = 3.5, fig.width = 3.75, fig.align = "center", fig.cap = "Line plot of atmospheric concentration of CO$_{2}$ from 1990 to 1994."}
394+
```{r 03-data-co2-line-3, warning = FALSE, message = FALSE, fig.height = 3.5, fig.width = 4.5, fig.align = "center", fig.cap = "Line plot of atmospheric concentration of CO$_{2}$ from 1990 to 1994."}
392395
library(lubridate)
393396
394397
co2_line <- ggplot(co2_df, aes(x = date_measured, y = ppm)) +
@@ -505,7 +508,7 @@ We will begin with a scatter plot of the `mother_tongue` and `most_at_home` colu
505508
The resulting plot is shown in Figure \@ref(fig:03-mother-tongue-vs-most-at-home).
506509
\index{ggplot!geom\_point}
507510

508-
```{r 03-mother-tongue-vs-most-at-home, fig.height=3.5, fig.width = 3.75, fig.align = "center", warning=FALSE, fig.cap = "Scatter plot of number of Canadians reporting a language as their mother tongue vs the primary language at home."}
511+
```{r 03-mother-tongue-vs-most-at-home, fig.height=5, fig.align = "center", warning=FALSE, fig.cap = "Scatter plot of number of Canadians reporting a language as their mother tongue vs the primary language at home."}
509512
ggplot(can_lang, aes(x = most_at_home, y = mother_tongue)) +
510513
geom_point()
511514
```
@@ -519,7 +522,7 @@ make the axes labels on the plots more readable.
519522
\index{escape character} We should also increase the font size to further
520523
improve readability.
521524

522-
```{r 03-mother-tongue-vs-most-at-home-labs, fig.height=3.8, fig.width = 4.5, fig.align = "center", warning=FALSE, 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."}
525+
```{r 03-mother-tongue-vs-most-at-home-labs, fig.height=5, fig.align = "center", warning=FALSE, 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."}
523526
ggplot(can_lang, aes(x = most_at_home, y = mother_tongue)) +
524527
geom_point() +
525528
labs(x = "Language spoken most at home \n (number of Canadian residents)",
@@ -584,7 +587,7 @@ to put commas in these numbers to increase their readability.
584587
We can do this in R by passing the `label_comma` function (from the `scales` package)
585588
to the `labels` argument of the `scale_x_log10` and `scale_x_log10` functions.
586589

587-
```{r 03-mother-tongue-vs-most-at-home-scale, message = FALSE, warning = FALSE, fig.height=3.8, fig.width = 4.5, fig.align = "center", fig.cap = "Scatter plot of number of Canadians reporting a language as their mother tongue vs the primary language at home with log adjusted x and y axes."}
590+
```{r 03-mother-tongue-vs-most-at-home-scale, message = FALSE, warning = FALSE, fig.height=5, fig.align = "center", fig.cap = "Scatter plot of number of Canadians reporting a language as their mother tongue vs the primary language at home with log adjusted x and y axes."}
588591
library(scales)
589592
590593
ggplot(can_lang, aes(x = most_at_home, y = mother_tongue)) +
@@ -641,7 +644,7 @@ Finally, we will edit the visualization to use the percentages we just computed
641644
units). Figure \@ref(fig:03-mother-tongue-vs-most-at-home-scale-props) displays
642645
the final result.
643646

644-
```{r 03-mother-tongue-vs-most-at-home-scale-props, fig.height=3.8, fig.width = 4.5, fig.align = "center", warning=FALSE, fig.cap = "Scatter plot of percentage of Canadians reporting a language as their mother tongue vs the primary language at home."}
647+
```{r 03-mother-tongue-vs-most-at-home-scale-props, fig.height=5, fig.align = "center", warning=FALSE, fig.cap = "Scatter plot of percentage of Canadians reporting a language as their mother tongue vs the primary language at home."}
645648
ggplot(can_lang, aes(x = most_at_home_percent, y = mother_tongue_percent)) +
646649
geom_point() +
647650
labs(x = "Language spoken most at home \n (percentage of Canadian residents)",
@@ -698,7 +701,7 @@ that the `category` column should color the points. Adding this argument will
698701
color the points according to their group and add a legend at the side of the
699702
plot.
700703

701-
```{r 03-scatter-color-by-category, warning=FALSE, fig.height=4, fig.width = 8, fig.align = "center", fig.cap = "Scatter plot of percentage of Canadians reporting a language as their mother tongue vs the primary language at home colored by language category."}
704+
```{r 03-scatter-color-by-category, warning=FALSE, fig.height=5, fig.align = "center", fig.cap = "Scatter plot of percentage of Canadians reporting a language as their mother tongue vs the primary language at home colored by language category."}
702705
ggplot(can_lang, aes(x = most_at_home_percent,
703706
y = mother_tongue_percent,
704707
color = category)) +
@@ -724,7 +727,7 @@ However, that will not work well for this particular visualization
724727
because the legend labels are quite long
725728
and would run off the page if displayed this way.
726729

727-
```{r 03-scatter-color-by-category-legend-edit, warning=FALSE, fig.height=5, fig.width = 5.5, fig.align = "center", fig.cap = "Scatter plot of percentage of Canadians reporting a language as their mother tongue vs the primary language at home colored by language category with the legend edited."}
730+
```{r 03-scatter-color-by-category-legend-edit, warning=FALSE, fig.height=5.5, fig.align = "center", fig.cap = "Scatter plot of percentage of Canadians reporting a language as their mother tongue vs the primary language at home colored by language category with the legend edited."}
728731
ggplot(can_lang, aes(x = most_at_home_percent,
729732
y = mother_tongue_percent,
730733
color = category)) +
@@ -770,7 +773,7 @@ this makes the scatter point shapes different for each category. This kind of
770773
visual redundancy&mdash;i.e., conveying the same information with both scatter point color and shape&mdash;can
771774
further improve the clarity and accessibility of your visualization.
772775

773-
```{r scatter-color-by-category-palette, fig.height=5, fig.width = 5.5, fig.align = "center", warning=FALSE, fig.cap = "Scatter plot of percentage of Canadians reporting a language as their mother tongue vs the primary language at home colored by language category with color-blind friendly colors."}
776+
```{r scatter-color-by-category-palette, fig.height=5.5, fig.align = "center", warning=FALSE, fig.cap = "Scatter plot of percentage of Canadians reporting a language as their mother tongue vs the primary language at home colored by language category with color-blind friendly colors."}
774777
ggplot(can_lang, aes(x = most_at_home_percent,
775778
y = mother_tongue_percent,
776779
color = category,

0 commit comments

Comments
 (0)