Style code + add alt text

This commit is contained in:
mine-cetinkaya-rundel 2023-05-25 21:07:33 -04:00
parent 5d7689a7a4
commit f323ade5cf
1 changed files with 18 additions and 1 deletions

View File

@ -219,7 +219,10 @@ ggplot(mpg, aes(x = displ, y = hwy)) +
geom_point() +
geom_text_repel(data = potential_outliers, aes(label = model)) +
geom_point(data = potential_outliers, color = "red") +
geom_point(data = potential_outliers, color = "red", size = 3, shape = "circle open")
geom_point(
data = potential_outliers,
color = "red", size = 3, shape = "circle open"
)
```
Remember, in addition to `geom_text()` and `geom_label()`, you have many other geoms in ggplot2 available to help annotate your plot.
@ -683,6 +686,13 @@ Subsetting the data has affected the x and y scales as well as the smooth curve.
#| layout-ncol: 2
#| fig-width: 4
#| message: false
#| fig-alt: |
#| On the left, scatterplot of highway mileage vs. displacement, with
#| displacement. The smooth curve overlaid shows a decreasing, and then
#| increasing trend, like a hockey stick. On the right, same variables
#| are plotted with displacement ranging only from 5 to 6 and highway
#| mileage ranging only from 10 to 25. The smooth curve overlaid shows a
#| trend that's slightly increasing first and then decreasing.
# Left
ggplot(mpg, aes(x = displ, y = hwy)) +
@ -706,6 +716,13 @@ Therefore, to zoom in on a region of the plot, it's generally best to use `coord
#| fig-width: 4
#| message: false
#| warning: false
#| fig-alt: |
#| On the left, scatterplot of highway mileage vs. displacement, with
#| displacement ranging from 5 to 6 and highway mileage ranging from
#| 10 to 25. The smooth curve overlaid shows a trend that's slightly
#| increasing first and then decreasing. On the right, same variables
#| are plotted with the same limits, however the smooth curve overlaid
#| shows a relatively flat trend with a slight increase at the end.
# Left
ggplot(mpg, aes(x = displ, y = hwy)) +