wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
655 stars 37 forks source link

ggtext with element_markdown(angle = x) turns into crooked text #117

Open CosmicOutlaw opened 5 months ago

CosmicOutlaw commented 5 months ago

Following code with ggtext library loaded

theme_minimal() +
  theme(
    axis.text.x = element_text(face = "bold"),
    axis.title.x = element_text(face = "bold"),
    axis.text.y = element_text(face = "bold"),
    axis.title.y = element_text(face = "bold"),
    legend.title = element_text(face = "bold"),
    axis.text.x.top = element_markdown(angle = 45),
    axis.title.x.top = element_blank(),
    plot.title = element_text(margin = margin(b = 10)),
    plot.subtitle = element_text(margin = margin(b = 20)),
    panel.grid.major = element_line(size = 1),
    panel.grid.minor = element_line(size = 1)
    ) +
  labs(
    title = "Varieties of Democracy across U.S. Presidents",

turns into this crooked text. Screenshot 2024-05-25 184657

Leaving angle at 0 or removing it entirely renders the text flawlessly.

ggtext can't render element_markdown with angle argument set to higher than 0.

bwiernik commented 5 months ago

In general, I would recommend using guides(x = guide_axis(angle = 30)) to set angled axis labels, rather theme(). Setting them with theme is an outdated and unpredictable approach.