You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
First, thanks for the great package! I have tried to use ggtext::element_markdown() with a title that is written in a rtl language (Arabic), but I'm seeing the result of the text becoming into reversed order. Below is a reprex with two ggplot2 plots, one using ggplot2::element_text() which renders the title in the correct order, a second is using ggtext::element_markdown() that renders the title in reverse order.
Requested Feature: Adding support to rtl languages in ggtext. Thanks a lot again!
library(ggplot2)
library(ggtext)
# Title is rendered in correct order when using ggplot2::element_text()ggplot2::ggplot(datasets::mtcars) +ggplot2::labs(
title="عنوان في اللغة العربية",
subtitle="Title is rendered in the correct order"
) +ggplot2::theme(
plot.title=ggplot2::element_text(size=20),
plot.subtitle=ggplot2::element_text(size=20)
)
# Title is rendered in reverse order when using ggtext::element_markdown()ggplot2::ggplot(datasets::mtcars) +ggplot2::labs(
title="عنوان في اللغة العربية",
subtitle="Title is rendered in reverse order"
) +ggplot2::theme(
plot.title=ggtext::element_markdown(size=20),
plot.subtitle=ggtext::element_markdown(size=20)
)
Yes, I'm aware. Unfortunately there is no easy way to fix this except via a complete rewrite of ggtext. I tried this a while back but those efforts are currently abandoned and I don't see myself picking them back up anytime soon.
The fundamental problem is that ggtext breaks the input text into individual words and then renders them one by one, from left to right. Consequently, a simple fix that you can employ is to just change the order of the words in the input string and the output should be correct. I know it's annoying, but it might be as simple as breaking string into individual tokens and assembling back in reverse order. Something like this:
Hello,
First, thanks for the great package! I have tried to use
ggtext::element_markdown()
with a title that is written in a rtl language (Arabic), but I'm seeing the result of the text becoming into reversed order. Below is a reprex with two ggplot2 plots, one usingggplot2::element_text()
which renders the title in the correct order, a second is usingggtext::element_markdown()
that renders the title in reverse order.Requested Feature: Adding support to rtl languages in ggtext. Thanks a lot again!
Created on 2024-03-19 with reprex v2.1.0
Session info
The text was updated successfully, but these errors were encountered: