From c9b0dffa27b5d0351542ee39ee606a63bc2a0be5 Mon Sep 17 00:00:00 2001 From: Sarah Stevens Date: Tue, 5 Dec 2023 10:24:30 -0600 Subject: [PATCH] Changing ggtitle function to use labs arg this was also changed in the r-socialsci lesson - https://github.com/datacarpentry/r-socialsci/issues/99 --- episodes/06-data-visualization.Rmd | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/episodes/06-data-visualization.Rmd b/episodes/06-data-visualization.Rmd index 8a07701c..60bc01a4 100644 --- a/episodes/06-data-visualization.Rmd +++ b/episodes/06-data-visualization.Rmd @@ -205,14 +205,14 @@ ggplot(data = variants, aes(x = POS, y = DP, color = sample_id)) + y = "Read Depth (DP)") ``` -To add a *main* title to the plot, we use [`ggtitle()`](https://ggplot2.tidyverse.org/reference/labs.html): +To add a *main* title to the plot, we use [the title argument for the `labs()` function](https://ggplot2.tidyverse.org/reference/labs.html): ```{r add-main-title, purl=FALSE} ggplot(data = variants, aes(x = POS, y = DP, color = sample_id)) + geom_point(alpha = 0.5) + labs(x = "Base Pair Position", - y = "Read Depth (DP)") + - ggtitle("Read Depth vs. Position") + y = "Read Depth (DP)", + title = "Read Depth vs. Position") ``` Now the figure is complete and ready to be exported and saved to a file. This can be achieved easily using [`ggsave()`](https://ggplot2.tidyverse.org/reference/ggsave.html), which can write, by default, the most recent generated figure into different formats (e.g., `jpeg`, `png`, `pdf`) according to the file extension. So, for example, to create a pdf version of the above figure with a dimension of $6\times4$ inches: @@ -252,8 +252,8 @@ To further customize the plot, we can change the default font format: ggplot(data = variants, aes(x = POS, y = DP, color = sample_id)) + geom_point(alpha = 0.5) + labs(x = "Base Pair Position", - y = "Read Depth (DP)") + - ggtitle("Read Depth vs. Position") + + y = "Read Depth (DP)", + title = "Read Depth vs. Position") + theme(text = element_text(family = "Bookman")) ```