Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scales-colour.qmd #407

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 8 additions & 5 deletions scales-colour.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,9 @@ If needed, you can adjust those options independently:
- `legend.box.just`: justification of each legend within the overall bounding box, when there are multiple legends ("top", "bottom", "left", or "right").

Alternatively, if there's a lot of blank space in your plot you might want to place the legend inside the plot.
You can do this by setting `legend.position` to a numeric vector of length two.
You can do this by setting `legend.position = "inside", legend.position.inside = c(...)` to a numeric vector of length two.
The numbers represent a relative location in the panel area: `c(0, 1)` is the top-left corner and `c(1, 0)` is the bottom-right corner.
You control which corner of the legend the `legend.position` refers to with `legend.justification`, which is specified in a similar way.
You control which corner of the legend the `legend.position.inside` refers to with `legend.justification`, which is specified in a similar way.
Unfortunately positioning the legend exactly where you want it requires a lot of trial and error.

```{r}
Expand All @@ -878,19 +878,22 @@ base <- ggplot(toy, aes(up, up)) +

base +
theme(
legend.position = c(0, 1),
legend.position = "inside",
legend.position.inside = c(0, 1)
legend.justification = c(0, 1)
)

base +
theme(
legend.position = c(0.5, 0.5),
legend.position = "inside",
legend.position.inside = c(0.5, 0.5),
legend.justification = c(0.5, 0.5)
)

base +
theme(
legend.position = c(1, 0),
legend.position = "inside",
legend.position.inside = c(1, 0),
legend.justification = c(1, 0)
)
```
Expand Down