title: Create barplot in R with gradient based on density
body: <p>I want to represent the density of a number of variables as you would in a boxplot, violin plot, or beeswarm. But in this case, each variable would be a band with the density displayed as a gradient along the bar.</p>
  
  <p>Hopefully I don't need to manually draw bars as filled shapes.</p>
  
  <p>Imagine if instead of the violins or boxplots, there was a bar with a gradient representing the density.</p>
  
  <p><a href="https://i.stack.imgur.com/yowCb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yowCb.png" alt="enter image description here"></a></p>
  
  <pre><code>library(tidyverse)
  library(ggplot)
  
  df = data.frame(
    A = 2.3 + 7*rnorm(100),
    B = 0 + 5*rnorm(100),
    C = 4 + 2*rnorm(100)
  )
  
  df %&gt;%
    gather() %&gt;%
    ggplot(aes(x=key, y=value)) + 
    geom_violin(scale="width", fill='red', alpha=0.5) + 
    geom_boxplot(fill='green', alpha=0.5)
  </code></pre>