title: Scatter smooth like in Excel (ggplot2 + plotly)
body: <p>I would like to mimic Excel smoothing style in R using ggplot2 and plotly.</p>
  
  <p>Packages</p>
  
  <pre><code>library(dplyr)
  library(tibble)
  library(ggplot2)
  library(plotly)
  library(ggforce) #only for geom_bspline() in example below (other smoothing functions can be used)
  library(scales) #only for percent() formatting below 
  </code></pre>
  
  <p>Example dataset</p>
  
  <pre><code>df &lt;- tibble(Group = rep(LETTERS[1:2], each = 10),
               x = rep(1:10, 2),
               y = c(2, 5, 9, 15, 19, 19, 15, 9, 5, 2,
                     1, 0, 3, 2, 3, 4, 14, 24, 24, 25)*0.01)
  </code></pre>
  
  <p>What I want</p>
  
  <p><a href="https://i.stack.imgur.com/SC0JN.png" rel="noreferrer"><img src="https://i.stack.imgur.com/SC0JN.png" alt="enter image description here"></a></p>
  
  <p>What I have so far</p>
  
  <pre><code>(df %&gt;%
      ggplot(aes(x, y)) +
      geom_point(aes(color = Group)) +
      ggforce::geom_bspline(aes(group = Group, color = Group)) +
      scale_y_continuous(limits = c(0, 0.35), labels = scales::percent) +
      scale_x_continuous(breaks = 1:10, minor_breaks = NULL) +
      theme_minimal()) %&gt;%
    ggplotly()
  </code></pre>
  
  <p>I know that overfitting is bad, but I need both lines to go straight through points (like in Excel). </p>
  
  <p>Solution might be pure plotly (gives more control than ggplotly() transformation).</p>
  
  <p>Additional, not required: Display Labels for points only (not smoothed curve)</p>