From 52edc8a67203b590f15295e21c11bc8abbc4e7e4 Mon Sep 17 00:00:00 2001 From: Tenstu <54093040+Tenstu@users.noreply.github.com> Date: Fri, 17 Jan 2025 21:25:14 +0800 Subject: [PATCH] Update scales-colour.qmd Update the usage of legend.position. From the [ggplot2 3.5.0 changelog]( https://ggplot2.tidyverse.org/news/index.html#ggplot2-350): Providing a numeric vector to theme(legend.position) has been deprecated. To set the default legend position inside the plot use theme(legend.position = "inside", legend.position.inside = c(...)) instead. --- scales-colour.qmd | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scales-colour.qmd b/scales-colour.qmd index 44d7893a..52d0436e 100644 --- a/scales-colour.qmd +++ b/scales-colour.qmd @@ -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} @@ -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) ) ```