1

I just updated my R to version 4.2. Ggtext, which was working fine until then now erase white spaces between words if the text is bold. I found a very similar question on RStudio forum but not a solution for me.

A reproducible example would be as follows (although maybe not that reproducible in other R versions, for it did work fine for me until this morning).

library(ggplot2)
library(ggtext)

p <- ggplot() +
  geom_blank() +
  labs(title = "A title with some words") +
  theme(plot.title = element_textbox_simple(
        face = "bold"))

p

enter image description here

And without bold:

library(ggplot2)
library(ggtext)

p <- ggplot() +
  geom_blank() +
  labs(title = "A title with some words") +
  theme(plot.title = element_textbox_simple())

p

enter image description here

Arthur Welle
  • 586
  • 5
  • 15
  • That works if I don´t want to use the capabilities of ggtext. I use element_textbox_simple() to automate break lines in long title text (my plots are on a function with variable title lenght). Or you are suggesting to call ggtext in other place (where?) other then theme()? [edit: this was a reply to a removed comment suggesting the use of element_text()] – Arthur Welle May 08 '22 at 13:23
  • 2
    I ran in the same issue today and it is actually a known issue (see https://github.com/wilkelab/ggtext/issues/83) which could be fixed by installing the development version of `gridtext`. – stefan May 09 '22 at 15:13
  • 1
    Thank yoy @stefan, that worked for me! I scanned the github issues by I guess I did let it pass unseen. Would you be so kind as to post this comment as an answer so that I could accept it? – Arthur Welle May 09 '22 at 15:51

1 Answers1

1

You can just use **bold text** to get your text bold:

library(ggplot2)
library(ggtext)

p <- ggplot() +
  geom_blank() +
  labs(title = "**A title with some words**") +
  theme(plot.title = element_textbox_simple())

p

Output:

enter image description here

Quinten
  • 35,235
  • 5
  • 20
  • 53
  • Thank you very much for your reply! Sadly this did not produce bold text for me... – Arthur Welle May 08 '22 at 18:51
  • @Arthur, which version did you use of `ggtext`? – Quinten May 08 '22 at 18:54
  • I used version 0.1.1. – Arthur Welle May 08 '22 at 19:01
  • Check this post: https://github.com/wilkelab/ggtext/issues/45. Maybe try and set in your `theme` `plot.title=element_markdown()`. – Quinten May 08 '22 at 19:08
  • 1
    Thanks again @Quinten, I tried multiple combinations of markdown code \*\*..\*\* or HTML tags ... and even CSS (...) with element_markdown() and element_textbox_simple() but was unable to get bold text. Strangely the thomas-neitmann post on the link that you provide does not generate bold text but it does generate color text (that is, the HTML/CSS tags work at least for colors). – Arthur Welle May 08 '22 at 19:53