From 338b484cf877d369232f29b8da287c00eab42cc3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 31 Mar 2026 17:24:38 +0000 Subject: [PATCH 1/4] Increase default element sizes ~20% and darken grid lines Agent-Logs-Url: https://github.com/yihui/gglite/sessions/5209206a-199c-42cd-a4ed-9fd9709eca79 Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com> --- DESCRIPTION | 2 +- R/gglite.R | 29 +++++++++++++++++++++++++++++ R/render.R | 10 +++++++++- tests/testit/test-gglite.R | 32 +++++++++++++++++++++++++++++++- 4 files changed, 70 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 714809a..bf77f95 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gglite Title: Lightweight Data Visualization via the Grammar of Graphics -Version: 0.0.4 +Version: 0.0.5 Authors@R: person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")) Description: A lightweight R interface to the AntV G2 JavaScript visualization diff --git a/R/gglite.R b/R/gglite.R index 13690e4..c7ee96a 100644 --- a/R/gglite.R +++ b/R/gglite.R @@ -20,6 +20,35 @@ g2_cdn = function() { g2_col_cdn = 'https://cdn.jsdelivr.net/npm/@xiee/utils/js/g2-column.min.js' +#' Default gglite Theme Overrides +#' +#' A list of G2 theme token overrides that are applied globally to every chart. +#' Increases element sizes (fonts, symbols) by ~20% compared to G2 defaults and +#' makes axis grid lines more visible. Customizable via +#' `options(gglite.theme = list(...))`. +#' +#' @keywords internal +.gglite_default_theme = list( + axis = list( + labelFontSize = 14, + titleFontSize = 14, + gridStrokeOpacity = 0.25 + ), + label = list(fontSize = 14), + innerLabel = list(fontSize = 14), + legendCategory = list( + itemLabelFontSize = 14, + itemValueFontSize = 14 + ), + point = list( + point = list(r = 3.6), + hollow = list(r = 3.6), + plus = list(r = 3.6), + diamond = list(r = 3.6) + ), + text = list(text = list(fontSize = 14)) +) + #' Create a G2 Chart Object #' #' Construct a base chart object, optionally with data and aesthetic mappings. diff --git a/R/render.R b/R/render.R index fab202a..5c056b8 100644 --- a/R/render.R +++ b/R/render.R @@ -33,7 +33,6 @@ build_config = function(chart) { if (length(chart$scales)) config$scale = chart$scales if (!is.null(chart$coords)) config$coordinate = chart$coords if (length(chart$interactions)) config$interaction = chart$interactions - if (!is.null(chart$theme)) config$theme = chart$theme if (length(chart$axes)) config$axis = chart$axes if (length(chart$legends)) config$legend = chart$legends if (!is.null(chart$chart_title)) config$title = chart$chart_title @@ -42,6 +41,15 @@ build_config = function(chart) { if (!is.null(chart$scrollbars)) config$scrollbar = chart$scrollbars if (length(chart$padding)) config = modifyList(config, chart$padding) + # Apply theme: merge global gglite defaults with chart-specific overrides. + # Use options(gglite.theme = list(...)) to customize or suppress defaults. + global_theme = getOption('gglite.theme', .gglite_default_theme) + config$theme = if (!is.null(chart$theme)) { + modifyList(global_theme, chart$theme) + } else { + global_theme + } + # Faceting wraps the spec as a facet view if (!is.null(chart$facet)) { config$type = chart$facet$type diff --git a/tests/testit/test-gglite.R b/tests/testit/test-gglite.R index ca6e521..ec1a38f 100644 --- a/tests/testit/test-gglite.R +++ b/tests/testit/test-gglite.R @@ -100,7 +100,37 @@ assert('animate() sets animation options', { (chart$layers[[1]]$animate$enter$type %==% 'fadeIn') }) -# theme_of(), axis_of(), legend_of(), title_of() set chart options +# build_config() applies global theme defaults and merges with user overrides +assert('build_config() applies global theme defaults', { + chart = g2(mtcars, x = 'mpg', y = 'hp') |> mark_point() + config = build_config(chart) + # default axis font size is 14 (not G2's 12) + (config$theme$axis$labelFontSize %==% 14) + (config$theme$axis$gridStrokeOpacity %==% 0.25) + (config$theme$label$fontSize %==% 14) +}) + +assert('build_config() merges user theme with global defaults', { + chart = g2(mtcars, x = 'mpg', y = 'hp') |> + mark_point() |> + theme_of('dark', axis = list(labelFontSize = 18)) + config = build_config(chart) + # user override wins + (config$theme$type %==% 'dark') + (config$theme$axis$labelFontSize %==% 18) + # default still preserved for other keys + (config$theme$label$fontSize %==% 14) +}) + +assert('gglite.theme option overrides global defaults', { + old = getOption('gglite.theme') + options(gglite.theme = list(axis = list(labelFontSize = 20))) + chart = g2(mtcars, x = 'mpg', y = 'hp') |> mark_point() + config = build_config(chart) + options(gglite.theme = old) + (config$theme$axis$labelFontSize %==% 20) +}) + assert('component functions set chart options', { chart = g2(mtcars, x = 'mpg', y = 'hp') |> mark_point() |> From f720ce52bc369a98bd1021a0c049e77f81711875 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 31 Mar 2026 18:44:29 +0000 Subject: [PATCH 2/4] JS theme registration, g2_defaults(), solid mark_point, +25% sizes Agent-Logs-Url: https://github.com/yihui/gglite/sessions/e37544b3-7851-472d-8617-fdb37517dde0 Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com> --- NAMESPACE | 1 + R/gglite.R | 51 +++++++++++++++++++------------------- R/mark.R | 10 +++++++- R/render.R | 23 ++++++++++------- inst/js/g2-defaults.js | 48 +++++++++++++++++++++++++++++++++++ man/g2_defaults.Rd | 29 ++++++++++++++++++++++ tests/testit/test-gglite.R | 49 ++++++++++++++++++++++-------------- 7 files changed, 156 insertions(+), 55 deletions(-) create mode 100644 inst/js/g2-defaults.js create mode 100644 man/g2_defaults.Rd diff --git a/NAMESPACE b/NAMESPACE index 481fd7e..6d8e504 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,6 +18,7 @@ export(facet_circle) export(facet_rect) export(g2) export(g2Output) +export(g2_defaults) export(interact) export(labels_of) export(legend_of) diff --git a/R/gglite.R b/R/gglite.R index c7ee96a..b98c420 100644 --- a/R/gglite.R +++ b/R/gglite.R @@ -20,34 +20,33 @@ g2_cdn = function() { g2_col_cdn = 'https://cdn.jsdelivr.net/npm/@xiee/utils/js/g2-column.min.js' -#' Default gglite Theme Overrides +#' Set or Get Global Chart Defaults #' -#' A list of G2 theme token overrides that are applied globally to every chart. -#' Increases element sizes (fonts, symbols) by ~20% compared to G2 defaults and -#' makes axis grid lines more visible. Customizable via -#' `options(gglite.theme = list(...))`. +#' Similar to [par()], get or set default theme options applied to all charts. +#' When set, these options are merged with per-chart [theme_of()] settings and +#' passed to G2. Chart size defaults (fonts, point size, grid opacity) are +#' applied automatically via a JavaScript patch loaded with every page. #' -#' @keywords internal -.gglite_default_theme = list( - axis = list( - labelFontSize = 14, - titleFontSize = 14, - gridStrokeOpacity = 0.25 - ), - label = list(fontSize = 14), - innerLabel = list(fontSize = 14), - legendCategory = list( - itemLabelFontSize = 14, - itemValueFontSize = 14 - ), - point = list( - point = list(r = 3.6), - hollow = list(r = 3.6), - plus = list(r = 3.6), - diamond = list(r = 3.6) - ), - text = list(text = list(fontSize = 14)) -) +#' @param ... Named theme options in the same structure accepted by [theme_of()], +#' e.g., `axis = list(labelFontSize = 16)`. Pass a single list (e.g., the +#' return value of a previous `g2_defaults()` call) to restore saved settings. +#' Pass `NULL` to clear all R-level defaults. +#' @return The previous defaults, invisibly (like [par()]). +#' @export +#' @examples +#' # Increase axis label size for all subsequent charts +#' old = g2_defaults(axis = list(labelFontSize = 18)) +#' g2(mtcars, x = 'mpg', y = 'hp') |> mark_point() +#' g2_defaults(old) # restore previous defaults +g2_defaults = function(...) { + prev = getOption('gglite.theme') + args = list(...) + if (!length(args)) return(invisible(prev)) + # A single unnamed arg is a saved value to restore (or NULL to clear) + val = if (length(args) == 1 && is.null(names(args))) args[[1]] else args + options(gglite.theme = val) + invisible(prev) +} #' Create a G2 Chart Object #' diff --git a/R/mark.R b/R/mark.R index b372389..4eb6b79 100644 --- a/R/mark.R +++ b/R/mark.R @@ -52,7 +52,15 @@ mark_line = function(chart, ...) mark(chart, 'line', ...) #' @export #' @examples #' g2(mtcars, x = 'mpg', y = 'hp', color = 'cyl') |> mark_point() -mark_point = function(chart, ...) mark(chart, 'point', ...) +mark_point = function(chart, ...) { + opts = list(...) + if (is.null(opts$style)) { + opts$style = list(shape = 'point') + } else if (is.null(opts$style$shape)) { + opts$style = modifyList(list(shape = 'point'), opts$style) + } + do.call(mark, c(list(chart, 'point'), opts)) +} #' Add an Area Mark #' diff --git a/R/render.R b/R/render.R index 5c056b8..f810fc0 100644 --- a/R/render.R +++ b/R/render.R @@ -41,14 +41,14 @@ build_config = function(chart) { if (!is.null(chart$scrollbars)) config$scrollbar = chart$scrollbars if (length(chart$padding)) config = modifyList(config, chart$padding) - # Apply theme: merge global gglite defaults with chart-specific overrides. - # Use options(gglite.theme = list(...)) to customize or suppress defaults. - global_theme = getOption('gglite.theme', .gglite_default_theme) - config$theme = if (!is.null(chart$theme)) { - modifyList(global_theme, chart$theme) - } else { - global_theme - } + # Theme: merge R-level g2_defaults() with per-chart theme_of() overrides. + # JS (g2-defaults.js) handles size/grid/shape defaults without R carrying them. + user_defaults = getOption('gglite.theme') + theme = if (length(user_defaults)) { + if (!is.null(chart$theme)) modifyList(user_defaults, chart$theme) + else user_defaults + } else chart$theme + if (!is.null(theme)) config$theme = theme # Faceting wraps the spec as a facet view if (!is.null(chart$facet)) { @@ -137,7 +137,12 @@ chart_html = function(chart, id = NULL, width = NULL, height = NULL) { } cdn_scripts = function() { - sprintf('', c(g2_cdn(), g2_col_cdn)) + js = readLines(system.file('js', 'g2-defaults.js', package = 'gglite'), + warn = FALSE) + c( + sprintf('', c(g2_cdn(), g2_col_cdn)), + paste0('') + ) } #' Preview a Chart in the Viewer or Browser diff --git a/inst/js/g2-defaults.js b/inst/js/g2-defaults.js new file mode 100644 index 0000000..15b4a68 --- /dev/null +++ b/inst/js/g2-defaults.js @@ -0,0 +1,48 @@ +// gglite: patch G2 theme defaults — larger fonts (~25%), visible grid lines +(function() { + // Deep-merge src keys into dest (src wins); returns new object + function merge(dest, src) { + var out = Object.assign({}, dest); + Object.keys(src).forEach(function(k) { + var sv = src[k], dv = dest ? dest[k] : undefined; + if (sv && typeof sv === 'object' && !Array.isArray(sv) && + dv && typeof dv === 'object') { + out[k] = merge(dv, sv); + } else { + out[k] = sv; + } + }); + return out; + } + + var overrides = { + axis: { + labelFontSize: 15, + titleFontSize: 15, + gridStrokeOpacity: 0.25 + }, + label: { fontSize: 15 }, + innerLabel: { fontSize: 15 }, + legendCategory: { + itemLabelFontSize: 15, + itemValueFontSize: 15 + }, + point: { + point: { r: 3.75 }, + hollow: { r: 3.75 }, + plus: { r: 3.75 }, + diamond: { r: 3.75 } + }, + text: { text: { fontSize: 15 } } + }; + + // Override each built-in G2 theme factory with our enhanced version + ['Classic', 'ClassicDark', 'Light', 'Dark', 'Academy'].forEach(function(name) { + var orig = G2[name]; + if (typeof orig !== 'function') return; + var key = 'theme:' + name.charAt(0).toLowerCase() + name.slice(1); + G2.register(key, function(options) { + return merge(orig(options), overrides); + }); + }); +})(); diff --git a/man/g2_defaults.Rd b/man/g2_defaults.Rd new file mode 100644 index 0000000..c8e32b8 --- /dev/null +++ b/man/g2_defaults.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gglite.R +\name{g2_defaults} +\alias{g2_defaults} +\title{Set or Get Global Chart Defaults} +\usage{ +g2_defaults(...) +} +\arguments{ +\item{...}{Named theme options in the same structure accepted by \code{\link[=theme_of]{theme_of()}}, +e.g., \code{axis = list(labelFontSize = 16)}. Pass a single list (e.g., the +return value of a previous \code{g2_defaults()} call) to restore saved settings. +Pass \code{NULL} to clear all R-level defaults.} +} +\value{ +The previous defaults, invisibly (like \code{\link[=par]{par()}}). +} +\description{ +Similar to \code{\link[=par]{par()}}, get or set default theme options applied to all charts. +When set, these options are merged with per-chart \code{\link[=theme_of]{theme_of()}} settings and +passed to G2. Chart size defaults (fonts, point size, grid opacity) are +applied automatically via a JavaScript patch loaded with every page. +} +\examples{ +# Increase axis label size for all subsequent charts +old = g2_defaults(axis = list(labelFontSize = 18)) +g2(mtcars, x = 'mpg', y = 'hp') |> mark_point() +g2_defaults(old) # restore previous defaults +} diff --git a/tests/testit/test-gglite.R b/tests/testit/test-gglite.R index ec1a38f..63be0b8 100644 --- a/tests/testit/test-gglite.R +++ b/tests/testit/test-gglite.R @@ -31,6 +31,19 @@ assert('mark_point() and mark_line() add layers', { (chart$layers[[2]]$type %==% 'line') }) +# mark_point() defaults to solid shape; user can override +assert('mark_point() defaults to solid shape and respects user override', { + chart = g2(mtcars, x = 'mpg', y = 'hp') |> mark_point() + (chart$layers[[1]]$style$shape %==% 'point') + chart2 = g2(mtcars, x = 'mpg', y = 'hp') |> + mark_point(style = list(shape = 'hollow')) + (chart2$layers[[1]]$style$shape %==% 'hollow') + chart3 = g2(mtcars, x = 'mpg', y = 'hp') |> + mark_point(style = list(opacity = 0.5)) + (chart3$layers[[1]]$style$shape %==% 'point') + (chart3$layers[[1]]$style$opacity %==% 0.5) +}) + # build_config() produces correct spec with column-major data assert('build_config() produces correct spec', { df = data.frame(x = c('A', 'B'), y = c(3, 7)) @@ -101,33 +114,31 @@ assert('animate() sets animation options', { }) # build_config() applies global theme defaults and merges with user overrides -assert('build_config() applies global theme defaults', { +assert('build_config() has no theme by default (JS handles defaults)', { chart = g2(mtcars, x = 'mpg', y = 'hp') |> mark_point() config = build_config(chart) - # default axis font size is 14 (not G2's 12) - (config$theme$axis$labelFontSize %==% 14) - (config$theme$axis$gridStrokeOpacity %==% 0.25) - (config$theme$label$fontSize %==% 14) + (is.null(config$theme)) }) -assert('build_config() merges user theme with global defaults', { - chart = g2(mtcars, x = 'mpg', y = 'hp') |> - mark_point() |> - theme_of('dark', axis = list(labelFontSize = 18)) +assert('g2_defaults() sets and restores global theme options', { + old = g2_defaults(axis = list(labelFontSize = 20)) + chart = g2(mtcars, x = 'mpg', y = 'hp') |> mark_point() config = build_config(chart) - # user override wins - (config$theme$type %==% 'dark') - (config$theme$axis$labelFontSize %==% 18) - # default still preserved for other keys - (config$theme$label$fontSize %==% 14) + g2_defaults(old) + (config$theme$axis$labelFontSize %==% 20) + (is.null(getOption('gglite.theme'))) }) -assert('gglite.theme option overrides global defaults', { - old = getOption('gglite.theme') - options(gglite.theme = list(axis = list(labelFontSize = 20))) - chart = g2(mtcars, x = 'mpg', y = 'hp') |> mark_point() +assert('g2_defaults() merges with per-chart theme_of()', { + old = g2_defaults(axis = list(labelFontSize = 20)) + chart = g2(mtcars, x = 'mpg', y = 'hp') |> + mark_point() |> + theme_of('dark', axis = list(titleFontSize = 18)) config = build_config(chart) - options(gglite.theme = old) + g2_defaults(old) + # per-chart type + titleFontSize win; labelFontSize from g2_defaults preserved + (config$theme$type %==% 'dark') + (config$theme$axis$titleFontSize %==% 18) (config$theme$axis$labelFontSize %==% 20) }) From 1b24683ac23746f7583a957f3ff74da007feda38 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 1 Apr 2026 00:45:52 +0000 Subject: [PATCH 3/4] Simplify R code: remove .theme_defaults and g2_defaults(), use g2-patches.min.js CDN, simplify mark_point() - Remove .theme_defaults from R/render.R (JS patches handle defaults now) - Remove g2_defaults() function; keep options('gglite.theme') support - Document gglite.theme option on theme_() help page with examples - Use g2-patches.min.js CDN instead of g2-column.min.js - Simplify mark_point() with modifyList as suggested - Update tests accordingly Agent-Logs-Url: https://github.com/yihui/gglite/sessions/138a6388-abcc-48a5-b429-01b53ab03171 Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com> --- NAMESPACE | 1 - R/gglite.R | 29 +---------------------------- R/mark.R | 7 +------ R/render.R | 23 +++++++---------------- R/theme.R | 15 +++++++++++++++ man/g2_defaults.Rd | 28 ---------------------------- man/theme_.Rd | 14 ++++++++++++++ tests/testit/test-gglite.R | 37 ++++++++----------------------------- 8 files changed, 46 insertions(+), 108 deletions(-) delete mode 100644 man/g2_defaults.Rd diff --git a/NAMESPACE b/NAMESPACE index ada3e57..87f735f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,7 +20,6 @@ export(facet_circle) export(facet_rect) export(g2) export(g2Output) -export(g2_defaults) export(interact) export(labels_) export(legend_) diff --git a/R/gglite.R b/R/gglite.R index ce00f11..017acf7 100644 --- a/R/gglite.R +++ b/R/gglite.R @@ -18,34 +18,7 @@ g2_cdn = function() { getOption('gglite.g2_cdn', 'https://unpkg.com/@antv/g2@5/dist/g2.min.js') } -g2_col_cdn = 'https://cdn.jsdelivr.net/npm/@xiee/utils/js/g2-column.min.js' - -#' Set or Get Global Chart Defaults -#' -#' Similar to [par()], get or set default theme options applied to all charts. -#' When set, these options are merged with per-chart [theme_()] settings and -#' passed to G2. -#' -#' @param ... Named theme options in the same structure accepted by [theme_()], -#' e.g., `axis = list(labelFontSize = 16)`. Pass a single list (e.g., the -#' return value of a previous `g2_defaults()` call) to restore saved settings. -#' Pass `NULL` to clear all R-level defaults. -#' @return The previous defaults, invisibly (like [par()]). -#' @export -#' @examples -#' # Increase axis label size for all subsequent charts -#' old = g2_defaults(axis = list(labelFontSize = 18)) -#' g2(mtcars, x = 'mpg', y = 'hp') |> mark_point() -#' g2_defaults(old) # restore previous defaults -g2_defaults = function(...) { - prev = getOption('gglite.theme') - args = list(...) - if (!length(args)) return(invisible(prev)) - # A single unnamed arg is a saved value to restore (or NULL to clear) - val = if (length(args) == 1 && is.null(names(args))) args[[1]] else args - options(gglite.theme = val) - invisible(prev) -} +g2_patches_cdn = 'https://cdn.jsdelivr.net/npm/@xiee/utils/js/g2-patches.min.js' #' Process a layout argument (padding, margin, or inset) #' diff --git a/R/mark.R b/R/mark.R index 23b6dd6..b6e17a0 100644 --- a/R/mark.R +++ b/R/mark.R @@ -55,12 +55,7 @@ mark_line = function(chart, ...) mark_(chart, 'line', ...) #' @examples #' g2(mtcars, x = 'mpg', y = 'hp', color = 'cyl') |> mark_point() mark_point = function(chart, ...) { - opts = list(...) - if (is.null(opts$style)) { - opts$style = list(shape = 'point') - } else if (is.null(opts$style$shape)) { - opts$style = modifyList(list(shape = 'point'), opts$style) - } + opts = modifyList(list(style = list(shape = 'point')), list(...)) do.call(mark_, c(list(chart, 'point'), opts)) } diff --git a/R/render.R b/R/render.R index a529e30..fbb10d4 100644 --- a/R/render.R +++ b/R/render.R @@ -1,14 +1,5 @@ # ---- Configuration builder ---- -# Base theme defaults: ~25% larger fonts and more visible grid lines than G2's -# built-in 12px / 0.1 opacity defaults. -.theme_defaults = list( - axis = list(labelFontSize = 15, titleFontSize = 15, gridStrokeOpacity = 0.25), - label = list(fontSize = 15), - innerLabel = list(fontSize = 15), - legendCategory = list(itemLabelFontSize = 15, itemValueFontSize = 15) -) - #' Build G2 Spec #' #' Convert a `g2` chart object into a nested list matching G2's @@ -50,12 +41,12 @@ build_config = function(chart) { if (!is.null(chart$scrollbars)) config$scrollbar = chart$scrollbars if (length(chart$layout)) config = modifyList(config, chart$layout) - # Theme: start with base defaults, merge g2_defaults(), then per-chart theme - theme = .theme_defaults - user_defaults = getOption('gglite.theme') - if (length(user_defaults)) theme = modifyList(theme, user_defaults) - if (!is.null(chart$theme)) theme = modifyList(theme, chart$theme) - config$theme = theme + # Theme: merge global option with per-chart theme + theme = getOption('gglite.theme') + if (!is.null(chart$theme)) { + theme = if (length(theme)) modifyList(theme, chart$theme) else chart$theme + } + if (length(theme)) config$theme = theme # Faceting wraps the spec as a facet view if (!is.null(chart$facet)) { @@ -144,7 +135,7 @@ chart_html = function(chart, id = NULL, width = NULL, height = NULL) { } cdn_scripts = function() { - sprintf('', c(g2_cdn(), g2_col_cdn)) + sprintf('', c(g2_cdn(), g2_patches_cdn)) } #' Preview a Chart in the Viewer or Browser diff --git a/R/theme.R b/R/theme.R index 8712c6d..3730c07 100644 --- a/R/theme.R +++ b/R/theme.R @@ -3,6 +3,21 @@ #' G2 built-in themes: `'classic'` (default), `'classicDark'`, `'light'`, #' `'dark'`, `'academy'`. #' +#' To set global theme options for all charts, use `options(gglite.theme = +#' list(...))`. This is useful for changing default font sizes, grid line +#' visibility, and other theme properties without modifying each chart +#' individually. For example: +#' +#' ```r +#' options(gglite.theme = list( +#' title = list(titleFontSize = 20), +#' axis = list(labelFontSize = 16, gridStrokeOpacity = 0.3), +#' legendCategory = list(itemLabelFontSize = 14) +#' )) +#' ``` +#' +#' Per-chart `theme_()` settings are merged on top of the global option. +#' #' @param chart A `g2` object. #' @param type Theme name string, or a list of custom theme options. #' @param ... Additional theme options merged with the type. diff --git a/man/g2_defaults.Rd b/man/g2_defaults.Rd deleted file mode 100644 index 50de0de..0000000 --- a/man/g2_defaults.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/gglite.R -\name{g2_defaults} -\alias{g2_defaults} -\title{Set or Get Global Chart Defaults} -\usage{ -g2_defaults(...) -} -\arguments{ -\item{...}{Named theme options in the same structure accepted by \code{\link[=theme_]{theme_()}}, -e.g., \code{axis = list(labelFontSize = 16)}. Pass a single list (e.g., the -return value of a previous \code{g2_defaults()} call) to restore saved settings. -Pass \code{NULL} to clear all R-level defaults.} -} -\value{ -The previous defaults, invisibly (like \code{\link[=par]{par()}}). -} -\description{ -Similar to \code{\link[=par]{par()}}, get or set default theme options applied to all charts. -When set, these options are merged with per-chart \code{\link[=theme_]{theme_()}} settings and -passed to G2. -} -\examples{ -# Increase axis label size for all subsequent charts -old = g2_defaults(axis = list(labelFontSize = 18)) -g2(mtcars, x = 'mpg', y = 'hp') |> mark_point() -g2_defaults(old) # restore previous defaults -} diff --git a/man/theme_.Rd b/man/theme_.Rd index 9e2035b..06ba7b4 100644 --- a/man/theme_.Rd +++ b/man/theme_.Rd @@ -20,6 +20,20 @@ The modified \code{g2} object. G2 built-in themes: \code{'classic'} (default), \code{'classicDark'}, \code{'light'}, \code{'dark'}, \code{'academy'}. } +\details{ +To set global theme options for all charts, use \code{options(gglite.theme = list(...))}. This is useful for changing default font sizes, grid line +visibility, and other theme properties without modifying each chart +individually. For example: + +\if{html}{\out{