3

I am using ggtext's element_markdown to modify a subtitle, and to add color to one word, that is in a plot_annotation layer. My code is as follows:

p1 + p1 + plot_layout(nrow = 2, heights = c(4, 1.8)) +
  plot_annotation(title = "The Rise of Electric Charging", 
                  # Using inline html  to change the color
                  subtitle = "Examining the increase in <span style='color:#668F82;'>electric charging</span> stations over time.") &
  theme(plot.title = element_text(color = "White", size = 30, family = "Comfortaa", face = "bold"),
        plot.subtitle = element_markdown(color = "White", size = 15, family = "Comfortaa", face = "bold", margin = margin(10, 0, 5, 0, "mm")),
        plot.background = element_rect(fill = "#2A2D34", colour = "#2A2D34"))

While this works, it expands the spacing between words/letters, as such:

enter image description here

Compare this to when the text is just an element_text item:

enter image description here

I'm wondeirng if anyone might have insights into why this is happening? For reference, when adding a title to the indivudal plots, the same issue occurs. However, in other files that I am working from, I am able to modify certain words using the same code.

wcbrown
  • 157
  • 7
  • I cannot confirm this on my machine: the spacing between words looks normal to me. What versions of ggtext, gridtext, ggplot2 and R are you using on which platform? Perhaps also relevant, which graphics device are you using for rendering the plot? – teunbrand Mar 02 '22 at 15:27
  • ggtext is 0.1.1, gridtext is 0.1.4, ggplot is 3.3.5, R 4.1.2. I'm using the default screen device to render. – wcbrown Mar 02 '22 at 17:12
  • Strange, I have the same versions. Does saving as pdf or png also show the extended word spacing? – teunbrand Mar 02 '22 at 18:07
  • It does... I've gone ahead and restarted my machine to no success. Strange! – wcbrown Mar 02 '22 at 19:01
  • I am having the same problem with spacing now. R version is 4.3.1, platform is x86_64-apple-darwin20, ggtext is 0.1.2, gridtext is 0.1.5, tidyverse is 2.0.0. Not sure what is the solution. – musthero Aug 31 '23 at 20:23

1 Answers1

0

I had the exact same issue here, and in my instance, I was able to replicate the bug on two Mac laptops, but not the windows laptop we also tested it on. We managed to solve the issue on Mac by switching R (and RStudio)'s graphical rendering to Ragg - maybe that'll help?