Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions episodes/04-data-viz-ggplot.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,27 @@
- use the `ggplot()` function and bind the plot to a specific data frame using
the `data` argument

::::::::::::::::::::::::::::::::::::::::::::; callout

Check warning on line 116 in episodes/04-data-viz-ggplot.Rmd

View workflow job for this annotation

GitHub Actions / Build markdown source files if valid

[unknown div] ::::::::::::::::::::::::::::::::::::::::::::; callout

**Note on Aesthetic Mappings:**
In our basic template the `aes()` function is used inside `ggplot()`.

```r
ggplot(data = <DATA>, mapping = aes(<MAPPINGS>)) + <GEOM_FUNCTION>()
```

This sets **global** aesthetics that apply to all layers you add later, such as, geoms and scales. You might sometimes see the aesthetics defined inside a specific geom function like so:

```r
ggplot(data = booksPlot) +
geom_histogram(aes(x = tot_chkout), binwidth = 10) +
scale_y_log10()
```

In this case, the aesthetic mapping is **local** to `geom_histogram()`. This approach lets you specify or override settings for that particular layer without affecting others. In short, using `aes()` globally means every layer inherits the same settings, while using it locally gives you the flexibility to tailor individual layers as needed.

::::::::::

When you run the `ggplot()` function, it plots directly to the Plots tab in the
Navigation Pane (lower right). Alternatively, you can assign a plot to an R
object, then call `print()`to view the plot in the Navigation Pane.
Expand Down
Loading