title: ggplot2 2d Density Weights
body: <p>I'm trying to plot some data with 2d density contours using ggplot2 in R.</p>
  
  <p>I'm getting one slightly odd result.</p>
  
  <p>First I set up my ggplot object:</p>
  
  <pre><code>p &lt;- ggplot(data, aes(x=Distance,y=Rate, colour = Company))
  </code></pre>
  
  <p>I then plot this with geom_points and geom_density2d. I want geom_density2d to be weighted based on the organisation's size (OrgSize variable). However when I add OrgSize as a weighting variable nothing changes in the plot:</p>
  
  <p>This:</p>
  
  <pre><code>p+geom_point()+geom_density2d()
  </code></pre>
  
  <p>Gives an identical plot to this:</p>
  
  <pre><code>p+geom_point()+geom_density2d(aes(weight = OrgSize))
  </code></pre>
  
  <p>However, if I do the same with a loess line using geom_smooth, the weighting does make a clear difference.</p>
  
  <p>This:</p>
  
  <pre><code>p+geom_point()+geom_smooth()
  </code></pre>
  
  <p>Gives a different plot to this:</p>
  
  <pre><code>p+geom_point()+geom_smooth(aes(weight=OrgSize))
  </code></pre>
  
  <p>I was wondering if I'm using density2d inappropriately, should I instead be using contour and supplying OrgSize as the 'height'? If so then why does geom_density2d accept a weighting factor?</p>
  
  <p>Code below:</p>
  
  <pre><code>require(ggplot2)
  
   Company &lt;- c("One","One","One","One","One","Two","Two","Two","Two","Two")
   Store &lt;- c(1,2,3,4,5,6,7,8,9,10)
   Distance &lt;- c(1.5,1.6,1.8,5.8,4.2,4.3,6.5,4.9,7.4,7.2)
   Rate &lt;- c(0.1,0.3,0.2,0.4,0.4,0.5,0.6,0.7,0.8,0.9)
   OrgSize &lt;- c(500,1000,200,300,1500,800,50,1000,75,800)
  
   data &lt;- data.frame(Company,Store,Distance,Rate,OrgSize)
  
   p &lt;- ggplot(data, aes(x=Distance,y=Rate))
  
   # Difference is apparent between these two
   p+geom_point()+geom_smooth()
   p+geom_point()+geom_smooth(aes(weight = OrgSize))
  
   # Difference is not apparent between these two
   p+geom_point()+geom_density2d()
   p+geom_point()+geom_density2d(aes(weight = OrgSize))
  </code></pre>