title: How to automatically choose a good ylim to read geom_labels in ggplot2 in R
body: <p>Suppose I write the following code with the <code>diamonds</code> dataset:</p>
  <pre><code>library(tidyverse)
  
  diamonds %&gt;% 
      group_by(cut) %&gt;% 
      summarize(total_value = sum(price, na.rm = TRUE)) %&gt;% 
      arrange(total_value) %&gt;% 
      mutate(cut = as_factor(cut)) %&gt;% 
      mutate(across(where(is.numeric), ~round(., 1))) %&gt;% 
      ggplot(aes(x = cut, y = total_value)) +
      geom_col(aes(fill = cut)) +
      theme(legend.position = &quot;note&quot;) +
      coord_flip() +
      geom_label(aes(label = paste0(&quot;$&quot;, total_value)), size = 6) +
      labs(title = &quot;Total Value of Diamonds by Cut&quot;, y = &quot;USD&quot;, x = &quot;&quot;) +
      theme(axis.text = element_text(size = rel(1)))
  </code></pre>
  <p>which outputs the following plot:</p>
  <p><a href="https://i.stack.imgur.com/srTSB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/srTSB.png" alt="enter image description here" /></a></p>
  <p>As you can see, it is impossible to read the last digit(s) of the first category (&quot;Ideal&quot;).</p>
  <p>So, my question is, I know I can simply write something like <code>coord_flip(ylim = c(0,80000000)</code> and this would solve the problem; however, what could I write instead for ggplot2 to automatically know by itself how much space it should provide in <code>ylim</code> for people to clearly read the <code>geom_label()</code>s without me having to do this manually?</p>
  <p>I'm trying to create an automatic Dashboard with multiple plots such as this, but I cannot manually tune every one of those, I need an automatic mechanism and I haven't found anything regarding this on StackOverflow for <code>geom_label()</code> specifically.</p>
  <p>Thanks.</p>