library(ggplot2);
cars
# A tibble: 50 × 2
speed dist
<dbl> <dbl>
1 4 2
2 4 10
3 7 4
4 7 22
5 8 16
6 9 10
7 10 18
8 10 26
9 10 34
10 11 17
# ℹ 40 more rows
Graphical poems with ggplot2.
```{r walkthrough, include = T}
ggplot(cars) +
aes(x = speed, y = dist) +
geom_point() +
geom_smooth() ```
ggplot(cars) +
aes(x = speed, y = dist) +
geom_point() +
geom_smooth()
::knit_code$get("walkthrough") knitr
<- ':::{focus-on="cr-.PLOTXXX"}\n.COMMENT, `.CODE`\n:::\n\n:::{#cr-.PLOTXXX}\n```{r .PLOTXXX}\n.LEADING\n .CODE\n```\n:::\n' cr_last_plot_construction
::knit_code$get("walkthrough") |>
knitrstr_remove("\\s*?\\+$") |>
tibble(code = _) |>
mutate(index = row_number()) |>
mutate(plot_name = paste("walkthrough", sep = "-", index)) |>
mutate(explosion = cr_last_plot_construction) |>
mutate(explosion = str_replace_all(explosion, ".PLOTXXX", plot_name)) |>
mutate(explosion = str_replace(explosion, ".COMMENT", "")) |>
mutate(explosion = str_replace_all(explosion, ".CODE", code)) |>
mutate(explosion = str_replace(explosion, ".LEADING", ifelse(index == 1, "", "last_plot() +"))) |>
pull(explosion) |>
cat(sep = "\n") ->
to_closeread
:::{focus-on="cr-walkthrough-1"}
, `ggplot(cars)`
:::
:::{#cr-walkthrough-1}
```{r walkthrough-1}
ggplot(cars)
```
:::
:::{focus-on="cr-walkthrough-2"}
, ` aes(x = speed, y = dist)`
:::
:::{#cr-walkthrough-2}
```{r walkthrough-2}
last_plot() +
aes(x = speed, y = dist)
```
:::
:::{focus-on="cr-walkthrough-3"}
, ` geom_point()`
:::
:::{#cr-walkthrough-3}
```{r walkthrough-3}
last_plot() +
geom_point()
```
:::
:::{focus-on="cr-walkthrough-4"}
, ` geom_smooth()`
:::
:::{#cr-walkthrough-4}
```{r walkthrough-4}
last_plot() +
geom_smooth()
```
:::