5

Below is a much simpler example of a complicated custom function I have written. In the full-length form of this function,

  • "layer1"corresponds to caption entered by the user,
  • "layer2" corresponds to results from a statistical test, and
  • "layer3" corresponds to details about the statistical test carried out.

But when all three layers are included in the caption, it looks something like this-

library(ggplot2)

ggplot(iris, aes(Species, Sepal.Length)) +
  geom_boxplot()  +
  labs(caption = substitute(atop(substitute(
    atop("layer1", "layer2")
  )
  , "layer3")))

Created on 2018-11-09 by the reprex package (v0.2.1)

So I wanted to figure out a way I can keep the text size constant for all three layers. I am actually not sure why the text size automatically changes in this context.

Is there a way I can prevent this from happening?

Indrajeet Patil
  • 4,673
  • 2
  • 20
  • 51

1 Answers1

4

I'm a little confused about the "substitute" in the plot, but perhaps the following solves the problem:

ggplot(iris, aes(Species, Sepal.Length)) +
  geom_boxplot()  +
  labs(caption = substitute(atop(
    atop(displaystyle("layer1"), displaystyle("layer2")), "layer3")))

enter image description here

Julius Vainora
  • 47,421
  • 9
  • 90
  • 102
  • Cool. Wasn't aware of `displaystyle(x)` and `textstyle(x)` functions (any reason to prefer the former over the latter?). The behavior I was getting was because `plotmath` defaults to `scriptstyle(x)` or `scriptscriptstyle(x)`? – Indrajeet Patil Nov 10 '18 at 13:22
  • 2
    @IndrajeetPatil, I immediately took `displaystyle` just because, in LaTeX documents, inline equations are somewhat smaller than display equations, and that's exactly the way to fix it there. Now it looks like `textstyle` is going to have somewhat less spacing, so you may see what you prefer. I'd guess that the default here is `scriptstyle`, and if you added, say, `atop`, it would be `scriptscriptstyle`. – Julius Vainora Nov 10 '18 at 13:30
  • Thanks. See my second part to the current question: https://stackoverflow.com/questions/53239765/preventing-centering-in-plotmath-for-multilayered-text Maybe you have some solution for this as well. – Indrajeet Patil Nov 10 '18 at 14:08