Left and right align axis text with exact spacing between

前端 未结 1 2308
执念已碎
执念已碎 2021-02-20 12:44

I have some y axis labels I want to have all the same spacing. The labels are composed of 2 variables and I\'d like to put the correct spacing in between to the left variable i

相关标签:
1条回答
  • 2021-02-20 13:12

    Your text strings are nicely spaced based on a monospace font (which is what R console uses).

    Setting the axis label's font family to a monospace font will give the correct alignment:

    ggplot(mtcars,
           aes(x = drat, y = label)) +
      geom_point() +
      theme(axis.text.y = element_text(family = "mono"))
    

    (Not the prettiest look, I know... But you get the basic idea. I haven't worked much with fonts in R & this is the only monospace font I can think of right now.)

    0 讨论(0)
提交回复
热议问题