Skip to content

Commit 6e3d115

Browse files
committed
adjusting plot sizes for scatterplots and line plots in viz
1 parent 1b2bad6 commit 6e3d115

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

viz.Rmd

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ default settings.
292292
knitr::include_graphics("img/ggplot_function_scatter.jpeg")
293293
```
294294

295-
```{r 03-data-co2-scatter, warning=FALSE, message=FALSE, fig.width = 5, fig.height = 4, fig.cap = "Scatter plot of atmospheric concentration of CO$_{2}$ over time."}
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."}
296296
co2_scatter <- ggplot(co2_df, aes(x = date_measured, y = ppm)) +
297297
geom_point()
298298
@@ -323,7 +323,7 @@ Let's now try to visualize the `co2_df` as a line plot
323323
with just the default arguments:
324324
\index{ggplot!geom\_line}
325325

326-
```{r 03-data-co2-line, warning=FALSE, message=FALSE, fig.width = 5, fig.height = 4, fig.cap = "Line plot of atmospheric concentration of CO$_{2}$ over time."}
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."}
327327
co2_line <- ggplot(co2_df, aes(x = date_measured, y = ppm)) +
328328
geom_line()
329329
@@ -355,7 +355,7 @@ change the font size, we use the `theme` function with the `text` argument:
355355
> Interested readers may consult the `theme` function documentation;
356356
> see the additional resources section at the end of this chapter.
357357
358-
```{r 03-data-co2-line-2, warning=FALSE, message=FALSE, fig.width = 5, fig.height = 4, fig.cap = "Line plot of atmospheric concentration of CO$_{2}$ over time with clearer axes and labels."}
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."}
359359
co2_line <- ggplot(co2_df, aes(x = date_measured, y = ppm)) +
360360
geom_line() +
361361
xlab("Year") +
@@ -388,7 +388,7 @@ to convert the character strings we provide to `c` to `date` vectors.
388388
> but is not loaded by it.
389389
> Hence we need to load it separately in the code below.
390390
391-
```{r 03-data-co2-line-3, warning = FALSE, message = FALSE, fig.width = 5, fig.height = 4, fig.cap = "Line plot of atmospheric concentration of CO$_{2}$ from 1990 to 1994."}
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."}
392392
library(lubridate)
393393
394394
co2_line <- ggplot(co2_df, aes(x = date_measured, y = ppm)) +
@@ -457,7 +457,7 @@ function with the `waiting` variable on the horizontal axis, the `eruptions`
457457
variable on the vertical axis, and the `geom_point` geometric object.
458458
The result is shown in Figure \@ref(fig:03-data-faithful-scatter).
459459

460-
```{r 03-data-faithful-scatter, warning=FALSE, message=FALSE, fig.width = 5, fig.height = 4, fig.cap = "Scatter plot of waiting time and eruption time."}
460+
```{r 03-data-faithful-scatter, warning=FALSE, message=FALSE, fig.height = 3.5, fig.width = 3.75, fig.align = "center", fig.cap = "Scatter plot of waiting time and eruption time."}
461461
faithful_scatter <- ggplot(faithful, aes(x = waiting, y = eruptions)) +
462462
geom_point()
463463
@@ -471,7 +471,7 @@ the points are generally nicely visually separated, and the pattern they form
471471
is clear. In order to refine the visualization, we need only to add axis
472472
labels and make the font more readable:
473473

474-
```{r 03-data-faithful-scatter-2, warning=FALSE, message=FALSE, fig.width = 5, fig.height = 4, fig.cap = "Scatter plot of waiting time and eruption time with clearer axes and labels."}
474+
```{r 03-data-faithful-scatter-2, warning=FALSE, message=FALSE, fig.height = 3.5, fig.width = 3.75, fig.align = "center", fig.cap = "Scatter plot of waiting time and eruption time with clearer axes and labels."}
475475
faithful_scatter <- ggplot(faithful, aes(x = waiting, y = eruptions)) +
476476
geom_point() +
477477
labs(x = "Waiting Time (mins)", y = "Eruption Duration (mins)") +
@@ -505,7 +505,7 @@ We will begin with a scatter plot of the `mother_tongue` and `most_at_home` colu
505505
The resulting plot is shown in Figure \@ref(fig:03-mother-tongue-vs-most-at-home).
506506
\index{ggplot!geom\_point}
507507

508-
```{r 03-mother-tongue-vs-most-at-home, fig.height=5, fig.width = 4, warning=FALSE, fig.cap = "Scatter plot of number of Canadians reporting a language as their mother tongue vs the primary language at home."}
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."}
509509
ggplot(can_lang, aes(x = most_at_home, y = mother_tongue)) +
510510
geom_point()
511511
```
@@ -519,7 +519,7 @@ make the axes labels on the plots more readable.
519519
\index{escape character} We should also increase the font size to further
520520
improve readability.
521521

522-
```{r 03-mother-tongue-vs-most-at-home-labs, fig.height=5, fig.width = 4, 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."}
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."}
523523
ggplot(can_lang, aes(x = most_at_home, y = mother_tongue)) +
524524
geom_point() +
525525
labs(x = "Language spoken most at home \n (number of Canadian residents)",
@@ -584,7 +584,7 @@ to put commas in these numbers to increase their readability.
584584
We can do this in R by passing the `label_comma` function (from the `scales` package)
585585
to the `labels` argument of the `scale_x_log10` and `scale_x_log10` functions.
586586

587-
```{r 03-mother-tongue-vs-most-at-home-scale, message = FALSE, warning = FALSE, fig.height=5, fig.width = 4, 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."}
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."}
588588
library(scales)
589589
590590
ggplot(can_lang, aes(x = most_at_home, y = mother_tongue)) +
@@ -641,7 +641,7 @@ Finally, we will edit the visualization to use the percentages we just computed
641641
units). Figure \@ref(fig:03-mother-tongue-vs-most-at-home-scale-props) displays
642642
the final result.
643643

644-
```{r 03-mother-tongue-vs-most-at-home-scale-props, fig.height=5, fig.width = 4, warning=FALSE, fig.cap = "Scatter plot of percentage of Canadians reporting a language as their mother tongue vs the primary language at home."}
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."}
645645
ggplot(can_lang, aes(x = most_at_home_percent, y = mother_tongue_percent)) +
646646
geom_point() +
647647
labs(x = "Language spoken most at home \n (percentage of Canadian residents)",
@@ -698,7 +698,7 @@ that the `category` column should color the points. Adding this argument will
698698
color the points according to their group and add a legend at the side of the
699699
plot.
700700

701-
```{r 03-scatter-color-by-category, warning=FALSE, fig.height=5, fig.width = 4, 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."}
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."}
702702
ggplot(can_lang, aes(x = most_at_home_percent,
703703
y = mother_tongue_percent,
704704
color = category)) +
@@ -724,7 +724,7 @@ However, that will not work well for this particular visualization
724724
because the legend labels are quite long
725725
and would run off the page if displayed this way.
726726

727-
```{r 03-scatter-color-by-category-legend-edit, warning=FALSE, fig.height=5.5, 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."}
727+
```{r 03-scatter-color-by-category-legend-edit, warning=FALSE, fig.height=5, fig.width = 6, 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."}
728728
ggplot(can_lang, aes(x = most_at_home_percent,
729729
y = mother_tongue_percent,
730730
color = category)) +
@@ -770,7 +770,7 @@ this makes the scatter point shapes different for each category. This kind of
770770
visual redundancy&mdash;i.e., conveying the same information with both scatter point color and shape&mdash;can
771771
further improve the clarity and accessibility of your visualization.
772772

773-
```{r scatter-color-by-category-palette, fig.height=5.5, 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."}
773+
```{r scatter-color-by-category-palette, fig.height=5, fig.width = 6, 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."}
774774
ggplot(can_lang, aes(x = most_at_home_percent,
775775
y = mother_tongue_percent,
776776
color = category,

0 commit comments

Comments
 (0)