Skip to content

Commit 626c366

Browse files
authored
Merge pull request #113 from LibraryCarpentry/data-vis-aes-global-local-callout
adding callout about aes global and local mappings
2 parents c7128ca + d3e3843 commit 626c366

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

episodes/04-data-viz-ggplot.Rmd

+21
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,27 @@ ggplot(data = <DATA>, mapping = aes(<MAPPINGS>)) + <GEOM_FUNCTION>()
113113
- use the `ggplot()` function and bind the plot to a specific data frame using
114114
the `data` argument
115115

116+
::::::::::::::::::::::::::::::::::::::::::::; callout
117+
118+
**Note on Aesthetic Mappings:**
119+
In our basic template the `aes()` function is used inside `ggplot()`.
120+
121+
```r
122+
ggplot(data = <DATA>, mapping = aes(<MAPPINGS>)) + <GEOM_FUNCTION>()
123+
```
124+
125+
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:
126+
127+
```r
128+
ggplot(data = booksPlot) +
129+
geom_histogram(aes(x = tot_chkout), binwidth = 10) +
130+
scale_y_log10()
131+
```
132+
133+
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.
134+
135+
::::::::::
136+
116137
When you run the `ggplot()` function, it plots directly to the Plots tab in the
117138
Navigation Pane (lower right). Alternatively, you can assign a plot to an R
118139
object, then call `print()`to view the plot in the Navigation Pane.

0 commit comments

Comments
 (0)