| Title: | A 'ggplot2' Extension for Translating Plot Text |
|---|---|
| Description: | Provides a simple way to translate text elements in 'ggplot2' plots using a dictionary-based approach. |
| Authors: | Mathias Leroy [aut, cre] |
| Maintainer: | Mathias Leroy <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.2 |
| Built: | 2026-06-09 06:21:33 UTC |
| Source: | https://github.com/mathiasleroy/ggtranslate |
This function takes a ggplot2 object and a named list to translate all user-facing text elements within the plot. This includes main plot labels (title, subtitle, captions, axis titles, legend titles), discrete axis tick labels, discrete legend keys, facet labels, and text from 'geom_text'/'geom_label'.
ggtranslate(plot, dictionary_list, mode = "strict")ggtranslate(plot, dictionary_list, mode = "strict")
plot |
A ggplot object whose text elements are to be translated. |
dictionary_list |
A named list (or named character vector) where the names are the original text and the values are the translated text. |
mode |
Translation mode: '"strict"' (default, exact match only), '"longfirst"' (partial replacement, longest key first), or '"asordered"' (partial replacement, as ordered in the dict). |
A modified ggplot object with all translatable text elements replaced according to the provided dictionary list.
library(ggplot2) df <- data.frame( day = factor(c("Monday", "Tuesday"), levels = c("Monday", "Tuesday")), value = c(10, 12) ) translation_fr <- list( "Monday" = "Lundi", "Tuesday" = "Mardi", "day" = "jour", "value" = "valeur", "Weekly Report" = "Rapport Hebdomadaire" ) p_en <- ggplot(df, aes(x = day, y = value)) + geom_col() + labs(title = "Weekly Report") p_fr <- ggtranslate(p_en, translation_fr)library(ggplot2) df <- data.frame( day = factor(c("Monday", "Tuesday"), levels = c("Monday", "Tuesday")), value = c(10, 12) ) translation_fr <- list( "Monday" = "Lundi", "Tuesday" = "Mardi", "day" = "jour", "value" = "valeur", "Weekly Report" = "Rapport Hebdomadaire" ) p_en <- ggplot(df, aes(x = day, y = value)) + geom_col() + labs(title = "Weekly Report") p_fr <- ggtranslate(p_en, translation_fr)