0

I am trying to reduce the space between the numerator, denominator, and fraction line in R expression. Here is my MWE generating a very ugly legend text for the fraction:

tibble(
  t = seq(0,60,.1),
  osc = cos(log2(1+t)*pi+pi/4)
) %>% 
  ggplot(aes(t, osc))+
  geom_line(aes(color = 'red'))+
  scale_color_manual(values = 'red', labels = expression(cos(log[2](t+1)*pi+frac(pi,4))+10))+
  theme(
    legend.position = 'bottom'
  )

The fraction introduces huge white space between the fraction line and numerator and denominator. Is there anyway to reduce this?

Baraliuh
  • 2,009
  • 5
  • 11

1 Answers1

0

I don't think there's a way to control spacing in plotmath, but you could use paste(pi,"/",4) instead of frac(pi, 4):

Before:

enter image description here

After:

enter image description here

user2554330
  • 37,248
  • 4
  • 43
  • 90
  • Naw, if I were to rewrite the equation, I would probably put `pi*4^{-1}` or `phantom('')^pi/phantom('')[4]` if I would have wanted a slash. That was not my interest in posting this question. – Baraliuh Oct 19 '21 at 21:58
  • I thought you *didn't* want ugly text in your legend. – user2554330 Oct 20 '21 at 07:20
  • I thought I wanted to reduce the space of the fraction, as per the first and last sentence. – Baraliuh Oct 20 '21 at 14:19