wcbrown
wcbrown

Reputation: 217

ggtext creates excessive white space between subtitle and title

I have created a plot in ggplot and am using ggtext to colorize particular words in my subtitle. While that works, every time that I render the plot, there is an excessive amount of white space at the top. The code that is helping with rendering the text is below, and this is the output. Any thoughts on what I should do?

  filter(threatened == 1,
         !is.na(year_last_seen)) %>%
  count(year_last_seen, threat_type) %>%
  pivot_wider(names_from = year_last_seen, values_from = n) %>%
  mutate_if(is.integer, as.numeric) %>% 
  mutate_all(~replace(., is.na(.), 0)) %>%
  nest(c('1900-1919', '1920-1939', '1940-1959', '1960-1979', '1980-1999', '2000-2020')) %>%
  mutate('2020_sum' = map_dbl(data, sum)) %>%
  unnest() %>%
  mutate(threat_type = fct_reorder(threat_type, `2020_sum`)) %>%
  ggplot() + 
  geom_dumbbell(aes(y = threat_type, x = `Before 1900`, xend = `2020_sum`), 
                color='#E7E3D9', size = 1.5,
                colour_x = '#1E5871', colour_xend = '#8F0700', 
                size_x = 4, size_xend = 4) + 
# This is the text that is helping me colorize particular words in the subtitle.  
labs(title = "Number of Plants Threated",
       subtitle = "Change from <b style='color:#1E5871'>< 1900</b> through <b style='color:#8F0700'>2020</b>",
       x = '',
       y = '') +
  theme(plot.subtitle = element_markdown())```

Upvotes: 1

Views: 535

Answers (0)

Related Questions