wilkelab / ggtext

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

element_markdown fails when y axis is moved to the right #108

Closed jarekbryk closed 7 months ago

jarekbryk commented 7 months ago

Hi,

I have observed a strange behaviour when working with plots with y axis on the right (scale_y_continuous(position = "right")). element_markdown formatting works fine on axis title when the axis is on the left of the plot, but markdown is not rendered when the axis is moved to the right. Is this a bug or am I missing something?

Thanks, Jarek

library(tidyverse)
library(ggtext)

# Works fine
mtcars %>% 
    ggplot() + aes(x = mpg, y = cyl) + geom_point() +
    labs(y = "Number of <sup>cylinders</sup>") +
    theme(axis.title.y = element_markdown())


# Fails
mtcars %>% 
    ggplot() + aes(x = mpg, y = cyl) + geom_point() +
    scale_y_continuous(position = "right") +
    labs(y = "Number of <sup>cylinders</sup>") +
    theme(axis.title.y = element_markdown())

Created on 2023-11-23 with reprex v2.0.2

bwiernik commented 7 months ago

Use theme(axis.title.y.right = element_markdown())

jarekbryk commented 7 months ago

🤦🏻‍♀️ Thank you!

bwiernik commented 7 months ago

No problem--it's super confusing. Based on the parameter names, I would expect axis.title.y and axis.title.x to apply to both sides, but they only apply to the left and bottom.