wilkelab / ggtext

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

Update documentation to explain how to change position of axis text #10

Closed z3tt closed 4 years ago

z3tt commented 4 years ago

Hi Claus,

thanks again for your wonderful contribution to the ggplot2-verse! I love this package and use it for almost all plots since then and it works like a charm - most of the time. I know it's a dev version so I just want to report a bug I've found (without expecting you to fix it soon):

options(warn = -1)

library(tidyverse)
library(ggtext)

theme_update(axis.text.x = element_markdown(size = 15))

labs <- c("**ten**", "<i>twenty</i>", "<span style='color:#0072B2'>thirty<span>")

## axis text modifications are working perfectly...
ggplot(mtcars, aes(mpg, cyl)) +
  geom_point() +
  scale_x_continuous(breaks = c(10, 20, 30),
                     labels = labs)


### ... until one changes their position:
ggplot(mtcars, aes(mpg, cyl)) +
  geom_point() +
  scale_x_continuous(position = "top",
                     breaks = c(10, 20, 30),
                     labels = labs)

Created on 2019-12-13 by the reprex package (v0.3.0)

All the best, Cédric

clauswilke commented 4 years ago

I think this is the same as issue #5. I'll have to add this to the documentation.

library(tidyverse)
library(ggtext)

theme_update(axis.text.x = element_markdown(size = 15))

labs <- c("**ten**", "<i>twenty</i>", "<span style='color:#0072B2'>thirty<span>")

ggplot(mtcars, aes(mpg, cyl)) +
  geom_point() +
  scale_x_continuous(breaks = c(10, 20, 30),
                     position = "top",
                     labels = labs) +
  theme(axis.text.x.top = element_markdown(size = 15))

Created on 2019-12-13 by the reprex package (v0.3.0)

z3tt commented 4 years ago

Yes, sorry wasn't searching through the closed issues since it's still relevant. Thanks for the quick feedback!

z3tt commented 4 years ago

Great, works perfectly! Thanks for the help!

clauswilke commented 4 years ago

See also: https://github.com/tidyverse/ggplot2/issues/3557

Facet strips genuinely don't work.

gadenbuie commented 4 years ago

This solution is also required for facet strip labels positioned on the left.

mtcars %>%
  group_by(cyl) %>%
  mutate(cyl_lab = as.character(
    glue("Cylinders {cyl} <span style='color:red'>(n={n()})</span>")
  )) %>%
  ggplot(aes(disp, mpg)) +
  geom_point() +
  facet_wrap(~cyl_lab, strip.position = "left") +
  theme(
    strip.text.y = element_markdown(), #<< doesn't work for left strip text
    strip.text.y.left = element_markdown() #<< does work
  )