1

With the code below, I get bold y-axis labels but not the x-axis. The issue is the output only when using math_format(). Curiously, the other aspects like angle, color, and size can be changed, but not the face of the font.

library(ggplot2)
library(scales)
a <- ggplot(msleep, aes(bodywt, brainwt)) +
  geom_point(na.rm = TRUE) +
  scale_x_log10(
    breaks = trans_breaks("log10", function(x) 10^x),
    labels = trans_format("log10", math_format(10^.x)))+
  scale_y_log10()+
  theme(axis.text.x = element_text(size=10, face="bold", color = "black"),
        axis.text.y = element_text(size=10, face="bold", color = "black"))
a
dnem
  • 57
  • 1
  • 6
  • 2
    Hello, found your question interesting. I do not have the answer but maybe [this](https://stackoverflow.com/questions/63673816/ggplot2-axis-text-formatting-wont-work-with-exponents) post will help you – Paul May 06 '21 at 08:49

1 Answers1

3

With direct copy/paste from the function https://stackoverflow.com/a/63674582/10264278 it works!

a <- ggplot(msleep, aes(bodywt, brainwt)) +
  geom_point(na.rm = TRUE) +
  scale_x_log10(
    breaks = trans_breaks("log10", function(x) 10^x),
    labels = function(lab) {
      do.call(
        expression,
        lapply(paste(lab), function(x) bquote(bold("10"^.(x))))
      )
    }) +
  scale_y_log10()+
  theme(axis.text.x = element_text(size=10, face="bold", color = "black"),
        axis.text.y = element_text(size=10, face="bold", color = "black"))
a

Output:

enter image description here

Paul
  • 2,850
  • 1
  • 12
  • 37