title: violin plot with constant data?
body: <p>I have some weird behaviour of <strong>violin plots</strong>, when the <strong>data is (in parts) constant</strong>.</p>
  
  <p>If I check for constant data and add some small errors artificially (e.g. by adding <code>runif( N, min = -0.001, max = 0.001 )</code>, the script will run. However, that distorts the other violin plot(s) to vertical line(s) (see <a href="https://i.stack.imgur.com/xpUlY.png" rel="nofollow noreferrer">1</a>), while it should look something like <a href="https://i.stack.imgur.com/AWEQ9.png" rel="nofollow noreferrer">2</a></p>
  
  <p><br>
  <strong>Question:</strong></p>
  
  <p>Is it possible (when the partial data for a violin plot is constant) to</p>
  
  <ul>
  <li>display a simple horizontal line for the respective constant data</li>
  <li>display the other violin plots, as if the constant data wasn't present?</li>
  </ul>
  
  <p><br>
  <strong>R code:</strong></p>
  
  <pre><code>library(ggplot2)
  library(grid)
  library(gridExtra)
  
  N &lt;- 20
  
  test_data &lt;- data.frame(
    idx  &lt;- c( 1:N, 1:N ),
    vals &lt;- c( runif(N, 0, 1),
               rep(  0.5, N)),                                         # &lt;- R script won't run
               #rep( 0.5, N) + runif( N, min = -0.001, max = 0.001 )), # &lt;- delivers graphic (distorted)
    type &lt;- c( rep("range",  N),
               rep("const",  N))
  )
  
  grid.arrange(
    ggplot( test_data, aes( x = idx, y = vals)) + 
      geom_line( aes(colour = type)),
    ggplot( test_data, aes( x = type, y = vals)) + 
      geom_violin( aes( fill = type),
                   position = position_dodge(width = 1))
  )
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/xpUlY.png" alt="distorted violin plots"></p>
  
  <p><img src="https://i.stack.imgur.com/AWEQ9.png" alt="the &#39;other&#39; violin plot"></p>