How to reduce the distance between text lines in ggplot axis?

Viewed 39

For one of the presentations, I am trying to make a scatter plot. Here is a similar code I am trying to run for the visualization I would like to have

library(tidyverse)
library(showtext)
library(ggtext)


ggplot(mtcars, aes(x = mpg, y = disp)) +
  geom_point(size = 1.5) +
  labs(title = "<span style = 'color:#005A9C;'>A vs. B</span>",
       x = "B<br>BBBBB<br>BBBBBBBBBB<br>BBBBBBBBBB",
       y = "A<br>AAAAA<br>AAAAAAAAAA<br>AAAAAAAAAA",
       caption = expression(paste(italic("Source:"), " JJJJJ"))) +
  theme_minimal() +
  theme(
    plot.background = element_rect(fill = "white",colour = NA),
    panel.background = element_rect(fill = 'white', colour = 'white'),
    panel.border = element_blank(),
    legend.position = "none",
    plot.title = element_markdown(hjust = 0.5, family = "title", size = 45),
    plot.subtitle = element_markdown(hjust = 0.5, family = "subtitle", size = 30), # note that to color numbers differently, I used element_markdown not element_text function
    axis.title.x = element_markdown(hjust = 0.5, family = "subtitle", size = 33),
    axis.text.x = element_markdown(hjust = 0.5, family = "subtitle", size = 20),
    axis.title.y = element_markdown(hjust = 0.5, family = "subtitle", size = 33),
    axis.text.y = element_markdown(hjust = 0.5, family = "subtitle", size = 20),
    plot.caption = element_text(hjust = 0, size = 21, family = "caption"))


ggsave("plot.png", height = 6, width = 7)

And here is the result;

enter image description here

Now, my question is how to reduce the distance between text lines for the x and y axes?

0 Answers
Related