Skip to content

Commit

Permalink
Start Chapter 20
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-Dahiya committed Sep 27, 2024
1 parent 9523c15 commit 457890e
Show file tree
Hide file tree
Showing 6 changed files with 352 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Chapter19.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ execute:
filters:
- social-share
share:
permalink: "https://aditya-dahiya.github.io/ggplot2book3e/Chapter17.html"
permalink: "https://aditya-dahiya.github.io/ggplot2book3e/Chapter19.html"
description: "Solutions Manual (and Beyond) for ggplot2: Elegant Graphics for Data Analysis (3e)"
twitter: true
facebook: true
Expand Down
57 changes: 54 additions & 3 deletions Chapter20.qmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,59 @@
---
title: "Chapter 20"
subtitle: "Extending ggplot2"
author: "Aditya Dahiya"
date: "2024-09-28"
format:
html:
code-fold: true
code-copy: hover
code-link: true
mermaid:
theme: neutral
execute:
echo: true
warning: false
error: false
cache: true
filters:
- social-share
share:
permalink: "https://aditya-dahiya.github.io/ggplot2book3e/Chapter20.html"
description: "Solutions Manual (and Beyond) for ggplot2: Elegant Graphics for Data Analysis (3e)"
twitter: true
facebook: true
linkedin: true
email: true
mastodon: true
editor_options:
chunk_output_type: console
bibliography: references.bib
---

::: callout-warning
Solutions for this chapter are under construction.
:::
::: {.callout-tip appearance="minimal"}
This chapter has no exercises. So, I will summarize the key take-aways.
:::

## 20.1 New Themes

- **20.1.1 Modifying themes:**
- Extending ggplot2 is easy and makes it flexible. Themes are the simplest extension type, often involving code similar to standard `ggplot2` plot styling.
- It is more practical to modify existing themes than create new ones from scratch.
- Example: `theme_minimal()` is built upon `theme_bw()` using the `%+replace%` operator to change specific elements.
- **20.1.2 Complete themes:**
- **Always define themes with `complete = TRUE` to ensure predictable behavior.**
- A complete theme helps users override settings like axis lines in a consistent manner.
- **20.1.3 Defining theme elements:**
- Themes in ggplot2 rely on an element tree, which defines each theme element and its inheritance.
- New theme elements can be added using `register_theme_elements()`.
- When defining new theme elements, include your package name as a prefix (e.g., `ggxyz.panel.annotation`) to avoid conflicts with other packages.

## 20.2 New Stats

- **20.2.1 Creating new stats:**
- Stats offer a powerful way to extend **ggplot2** by focusing on data transformations rather than visuals.
- While users may prefer to work with geoms, many geoms differ because they utilize different stats.
- New stats are defined using ggproto objects, specifically by implementing the **`compute_group()`** method, which handles data transformation for each group.
- It's often a good idea to create both stat\_*() and geom\_*() constructors, as users are more accustomed to geoms.
- **20.2.2 Modifying parameters and data:**
- New stats may require additional setup through `setup_params()` and `setup_data()` methods to modify parameters or data before the main computation.
2 changes: 1 addition & 1 deletion docs/Chapter19.html
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ <h1 class="title">Chapter 19</h1>
</script>
</div> <!-- /content -->
<footer class="footer"><div class="nav-footer"><div class="nav-footer-center"><div class="toc-actions d-sm-block d-md-none"><ul><li><a href="https://github.com/Aditya-Dahiya/ggplot2book3e/edit/main/Chapter19.qmd" class="toc-action"><i class="bi bi-github"></i>Edit this page</a></li><li><a href="https://github.com/Aditya-Dahiya/ggplot2book3e/issues/new" class="toc-action"><i class="bi empty"></i>Report an issue</a></li></ul></div></div></div></footer><div class="page-columns page-rows-contents page-layout-article"><div class="social-share">
<a href="https://twitter.com/share?url=https://aditya-dahiya.github.io/ggplot2book3e/Chapter17.html&amp;text=Solutions%20Manual%20(and%20Beyond)%20for%20ggplot2:%20Elegant%20Graphics%20for%20Data%20Analysis%20(3e)" target="_blank" class="twitter"><i class="fab fa-twitter fa-fw fa-lg"></i></a><a href="https://www.linkedin.com/shareArticle?url=https://aditya-dahiya.github.io/ggplot2book3e/Chapter17.html&amp;title=Solutions%20Manual%20(and%20Beyond)%20for%20ggplot2:%20Elegant%20Graphics%20for%20Data%20Analysis%20(3e)" target="_blank" class="linkedin"><i class="fa-brands fa-linkedin-in fa-fw fa-lg"></i></a> <a href="mailto:?subject=Solutions%20Manual%20(and%20Beyond)%20for%20ggplot2:%20Elegant%20Graphics%20for%20Data%20Analysis%20(3e)&amp;body=Check%20out%20this%20link:https://aditya-dahiya.github.io/ggplot2book3e/Chapter17.html" target="_blank" class="email"><i class="fa-solid fa-envelope fa-fw fa-lg"></i></a><a href="https://www.facebook.com/sharer.php?u=https://aditya-dahiya.github.io/ggplot2book3e/Chapter17.html" target="_blank" class="facebook"><i class="fab fa-facebook-f fa-fw fa-lg"></i></a><a href="javascript:void(0);" onclick="var mastodon_instance=prompt('Mastodon Instance / Server Name?'); if(typeof mastodon_instance==='string' &amp;&amp; mastodon_instance.length){this.href='https://'+mastodon_instance+'/share?text=Solutions Manual (and Beyond) for ggplot2: Elegant Graphics for Data Analysis (3e) https://aditya-dahiya.github.io/ggplot2book3e/Chapter17.html'}else{return false;}" target="_blank" class="mastodon"><i class="fa-brands fa-mastodon fa-fw fa-lg"></i></a>
<a href="https://twitter.com/share?url=https://aditya-dahiya.github.io/ggplot2book3e/Chapter19.html&amp;text=Solutions%20Manual%20(and%20Beyond)%20for%20ggplot2:%20Elegant%20Graphics%20for%20Data%20Analysis%20(3e)" target="_blank" class="twitter"><i class="fab fa-twitter fa-fw fa-lg"></i></a><a href="https://www.linkedin.com/shareArticle?url=https://aditya-dahiya.github.io/ggplot2book3e/Chapter19.html&amp;title=Solutions%20Manual%20(and%20Beyond)%20for%20ggplot2:%20Elegant%20Graphics%20for%20Data%20Analysis%20(3e)" target="_blank" class="linkedin"><i class="fa-brands fa-linkedin-in fa-fw fa-lg"></i></a> <a href="mailto:?subject=Solutions%20Manual%20(and%20Beyond)%20for%20ggplot2:%20Elegant%20Graphics%20for%20Data%20Analysis%20(3e)&amp;body=Check%20out%20this%20link:https://aditya-dahiya.github.io/ggplot2book3e/Chapter19.html" target="_blank" class="email"><i class="fa-solid fa-envelope fa-fw fa-lg"></i></a><a href="https://www.facebook.com/sharer.php?u=https://aditya-dahiya.github.io/ggplot2book3e/Chapter19.html" target="_blank" class="facebook"><i class="fab fa-facebook-f fa-fw fa-lg"></i></a><a href="javascript:void(0);" onclick="var mastodon_instance=prompt('Mastodon Instance / Server Name?'); if(typeof mastodon_instance==='string' &amp;&amp; mastodon_instance.length){this.href='https://'+mastodon_instance+'/share?text=Solutions Manual (and Beyond) for ggplot2: Elegant Graphics for Data Analysis (3e) https://aditya-dahiya.github.io/ggplot2book3e/Chapter19.html'}else{return false;}" target="_blank" class="mastodon"><i class="fa-brands fa-mastodon fa-fw fa-lg"></i></a>
</div></div>


Expand Down
Loading

0 comments on commit 457890e

Please sign in to comment.