Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should theme inheritance prefer the 'richer' element? #5457

Closed
teunbrand opened this issue Oct 5, 2023 · 0 comments · Fixed by #5486
Closed

Should theme inheritance prefer the 'richer' element? #5457

teunbrand opened this issue Oct 5, 2023 · 0 comments · Fixed by #5486

Comments

@teunbrand
Copy link
Collaborator

Sometimes, one thinks that one has set a theme element, but it turns out some downstream theme element overrides your settings.
In the example below, I want the markdown element to display the x-axis title in bold. However, it doesn't because axis.title.x already is a defined theme element in the default theme, which overrules the element_markdown().

library(ggplot2)

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  labs(x = "**displacement**")

p + theme(axis.title = ggtext::element_markdown())

Of course, there are plenty of ways to display the axis title in bold, such as setting a more appropriate theme element.

p + theme(axis.title.x = ggtext::element_markdown())

Since <element_markdown> is a subclass of <element_text>, I think it would be appropriate that the calculation below returns an <element_markdown> object.

calc_element(
  "axis.text.x.top",
  theme_get() + theme(axis.text = ggtext::element_markdown(colour = "red"))
)
#> List of 11
#>  $ family       : chr ""
#>  $ face         : chr "plain"
#>  $ colour       : chr "red"
#>  $ size         : num 8.8
#>  $ hjust        : num 0.5
#>  $ vjust        : num 0
#>  $ angle        : num 0
#>  $ lineheight   : num 0.9
#>  $ margin       : 'margin' num [1:4] 0points 0points 2.2points 0points
#>   ..- attr(*, "unit")= int 8
#>  $ debug        : logi FALSE
#>  $ inherit.blank: logi TRUE
#>  - attr(*, "class")= chr [1:2] "element_text" "element"

Created on 2023-10-05 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant