Skip to content

Commit 0d3757d

Browse files
Fix the YAML syntax of fig.alt chunk option (#6083)
1 parent ce4bce2 commit 0d3757d

10 files changed

+191
-201
lines changed

README.Rmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pak::pak("tidyverse/ggplot2")
4747
It's hard to succinctly describe how ggplot2 works because it embodies a deep philosophy of visualisation. However, in most cases you start with `ggplot()`, supply a dataset and aesthetic mapping (with `aes()`). You then add on layers (like `geom_point()` or `geom_histogram()`), scales (like `scale_colour_brewer()`), faceting specifications (like `facet_wrap()`) and coordinate systems (like `coord_flip()`).
4848

4949
```{r example}
50-
#| fig.alt = "Scatterplot of engine displacement versus highway miles per
50+
#| fig.alt: "Scatterplot of engine displacement versus highway miles per
5151
#| gallon, for 234 cars coloured by 7 'types' of car. The displacement and miles
5252
#| per gallon are inversely correlated."
5353
library(ggplot2)

vignettes/articles/faq-annotation.Rmd

+12-12
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ You should use `annotate(geom = "text")` instead of `geom_text()` for annotation
3939
In the following visualisation we have annotated a histogram with a red line and red text to mark the mean. Note that both the line and the text appears pixellated/fuzzy.
4040

4141
```{r}
42-
#| fig.alt = "Histogram of highway miles per gallon for 234 cars. A red line is
42+
#| fig.alt: "Histogram of highway miles per gallon for 234 cars. A red line is
4343
#| placed at the position 23.44 and is adorned with the label 'mean 23.44'.
4444
#| Both the line and the text appear pixellated due to overplotting."
4545
mean_hwy <- round(mean(mpg$hwy), 2)
@@ -62,7 +62,7 @@ This is because `geom_text()` draws the geom once per each row of the data frame
6262

6363

6464
```{r}
65-
#| fig.alt = "Histogram of highway miles per gallon for 234 cars. A red line is
65+
#| fig.alt: "Histogram of highway miles per gallon for 234 cars. A red line is
6666
#| placed at the position 23.44 and is adorned with the label 'mean = 23.44'.
6767
#| Both the line and the text appear crisp."
6868
ggplot(mpg, aes(x = hwy)) +
@@ -91,7 +91,7 @@ Set `vjust = "inward"` and `hjust = "inward"` in `geom_text()`.
9191
Suppose you have the following data frame and visualization. The labels at the edges of the plot are cut off slightly.
9292

9393
```{r}
94-
#| fig.alt = "A plot showing the words 'two', 'three' and 'four' arranged
94+
#| fig.alt: "A plot showing the words 'two', 'three' and 'four' arranged
9595
#| diagonally. The 'two' and 'four' labels have been clipped to the panel's
9696
#| edge and are not displayed completely."
9797
df <- tibble::tribble(
@@ -108,7 +108,7 @@ ggplot(df, aes(x = x, y = y, label = name)) +
108108
You could manually extend axis limits to avoid this, but a more straightforward approach is to set `vjust = "inward"` and `hjust = "inward"` in `geom_text()`.
109109

110110
```{r}
111-
#| fig.alt = "A plot showing the words 'two', 'three' and 'four' arranged
111+
#| fig.alt: "A plot showing the words 'two', 'three' and 'four' arranged
112112
#| diagonally. The 'two' and 'four' labels are aligned to the top-right and
113113
#| bottom-left relative to their anchor points, and are displayed in their
114114
#| entirety."
@@ -129,7 +129,7 @@ Either calculate the counts ahead of time and place them on bars using `geom_tex
129129
Suppose you have the following bar plot and you want to add the number of cars that fall into each `drv` level on their respective bars.
130130

131131
```{r}
132-
#| fig.alt = "A bar chart showing the number of cars for each of three types
132+
#| fig.alt: "A bar chart showing the number of cars for each of three types
133133
#| of drive train."
134134
ggplot(mpg, aes(x = drv)) +
135135
geom_bar()
@@ -139,7 +139,7 @@ One option is to calculate the counts with `dplyr::count()` and then pass them t
139139
Note that we expanded the y axis limit to get the numbers to fit on the plot.
140140

141141
```{r}
142-
#| fig.alt = "A bar chart showing the number of cars for each of three types
142+
#| fig.alt: "A bar chart showing the number of cars for each of three types
143143
#| of drive train. The count values are displayed on top of the bars as text."
144144
mpg %>%
145145
dplyr::count(drv) %>%
@@ -152,7 +152,7 @@ mpg %>%
152152
Another option is to let `ggplot()` do the counting for you, and access these counts with `after_stat(count)` that is mapped to the labels to be placed on the plot with `stat_count()`.
153153

154154
```{r}
155-
#| fig.alt = "A bar chart showing the number of cars for each of three types
155+
#| fig.alt: "A bar chart showing the number of cars for each of three types
156156
#| of drive train. The count values are displayed on top of the bars as text."
157157
ggplot(mpg, aes(x = drv)) +
158158
geom_bar() +
@@ -173,7 +173,7 @@ First calculate the counts for each segment (e.g. with `dplyr::count()`) and the
173173
Suppose you have the following stacked bar plot.
174174

175175
```{r}
176-
#| fig.alt = "A stacked bar chart showing the number of cars for each of seven
176+
#| fig.alt: "A stacked bar chart showing the number of cars for each of seven
177177
#| types of cars. The fill colour of the bars indicate the type of drive
178178
#| train."
179179
ggplot(mpg, aes(x = class, fill = drv)) +
@@ -190,7 +190,7 @@ mpg %>%
190190
You can then pass this result directly to `ggplot()`, draw the segments with appropriate heights with `y = n` in the `aes`thetic mapping and `geom_col()` to draw the bars, and finally place the counts on the plot with `geom_text()`.
191191

192192
```{r}
193-
#| fig.alt = "A stacked bar chart showing the number of cars for each of seven
193+
#| fig.alt: "A stacked bar chart showing the number of cars for each of seven
194194
#| types of cars. The fill colour of the bars indicate the type of drive
195195
#| train. In the middle of each filled part, the count value is displayed as
196196
#| text."
@@ -214,7 +214,7 @@ Either calculate the proportions ahead of time and place them on bars using `geo
214214
Suppose you have the following bar plot but you want to display the proportion of cars that fall into each `drv` level, instead of the count.
215215

216216
```{r}
217-
#| fig.alt = "A bar chart showing the number of cars for each of three types
217+
#| fig.alt: "A bar chart showing the number of cars for each of three types
218218
#| of drive train."
219219
ggplot(mpg, aes(x = drv)) +
220220
geom_bar()
@@ -223,7 +223,7 @@ ggplot(mpg, aes(x = drv)) +
223223
One option is to calculate the proportions with `dplyr::count()` and then use `geom_col()` to draw the bars
224224

225225
```{r}
226-
#| fig.alt = "A bar chart showing the proportion of cars for each of three types
226+
#| fig.alt: "A bar chart showing the proportion of cars for each of three types
227227
#| of drive train."
228228
mpg %>%
229229
dplyr::count(drv) %>%
@@ -236,7 +236,7 @@ Another option is to let `ggplot()` do the calculation of proportions for you, a
236236
Note that we also need to the `group = 1` mapping for this option.
237237

238238
```{r}
239-
#| fig.alt = "A bar chart showing the proportion of cars for each of three types
239+
#| fig.alt: "A bar chart showing the proportion of cars for each of three types
240240
#| of drive train."
241241
ggplot(mpg, aes(x = drv, y = ..prop.., group = 1)) +
242242
geom_bar()

0 commit comments

Comments
 (0)