From 24573e04ed802b41c9c775e13bd90151b51d26f5 Mon Sep 17 00:00:00 2001 From: AsherDB Date: Thu, 3 Apr 2025 18:49:03 +0100 Subject: [PATCH] Update theme_af.R In respose to https://github.com/best-practice-and-impact/afcharts/issues/47 Added option of "topleft" legend position that sets the legend.position = "top" and the legend.justification = c(0,0) so the legend is at the top left of the chart. --- R/theme_af.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/theme_af.R b/R/theme_af.R index f48452d..7d073f0 100644 --- a/R/theme_af.R +++ b/R/theme_af.R @@ -30,7 +30,7 @@ theme_af <- function(base_size = 14, grid = c("y", "x", "xy", "none"), axis = c("x", "y", "xy", "none"), ticks = c("xy", "x", "y", "none"), - legend = c("right", "left", "top", "bottom", "none")) { + legend = c("right", "left", "top", "bottom", "none", "topleft")) { grid <- match.arg(grid) axis <- match.arg(axis) @@ -158,9 +158,9 @@ theme_af <- function(base_size = 14, legend.text.align = NULL, legend.title = ggplot2::element_text(hjust = 0), legend.title.align = NULL, - legend.position = legend, + legend.position = ifelse(legend == "topleft", "top", legend), legend.direction = NULL, - legend.justification = "centre", + legend.justification = ifelse(legend == "topleft", c(0,0),"centre"), legend.box = NULL, legend.box.margin = ggplot2::margin(0, 0, 0, 0, "cm"), legend.box.background = ggplot2::element_blank(),