title: ggplot2: passing a continuous variable to "shape" within a wrapper
body: <p>So I'm trying to write a function which creates scatter plots. </p>
  
  <p>Depending on the data, I may want the value of V1 or V2 to determine the shape/colour of the point. The data in V1 only takes particular values, as does V2, but both look continuous to R/ggplot so I treat them <code>as.factor</code>. I might also regress buy V1 or V2.</p>
  
  <p>This works fine:</p>
  
  <pre><code>p1&lt;-ggplot(sigmas.table,
             aes(x=V4,y=V5, color=as.factor(V2),shape=as.factor(V1)))+  
      geom_point(size=4)+
      stat_smooth(aes(group=as.factor(V2)),method=lm,formula=y~poly(x,1),size=1)
  </code></pre>
  
  <p>But to wrap this in a function, first I have to switch to <code>aes_string</code> so that I can read in the colum titles (I also vary the x-axis value), but now I cant convince ggplot that V1/V2 only take a finite number of values to assign different points to. colour sort of works, but assigns a continuous shade rather than different colours, so it too is treating the data as continuous:</p>
  
  <pre><code>scatter.plot&lt;- function(s.table,x.var, col.var, shape.var, line.var){
                ploti &lt;- ggplot(s.table,
                                aes_string(x=x.var,y="V5", color=as.factor(col.var),shape=as.factor(shape.var)))+
                         geom_point(size=4)+
                         stat_smooth(aes_string(group=as.factor(line.var)),method=lm,formula=y~poly(x,1),size=1)+
                 return(ploti)}
  
  p1 &lt;- scatter.plot(sigmas.table,"V4","V2","V1","V2")
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>Error: A continuous variable can not be mapped to shape
  </code></pre>
  
  <p>I'm sure there are plenty of kludges available, but it seems to me (perhaps in my naivete) like there could be a real solution. Any and all help appreciated.</p>
  
  <p>P.s.
  here's a sample of the sigmas table:</p>
  
  <pre><code>     V1  V2         V3        V4         V5         V6
   1: 0.3  16 0.12791584 0.3454941 0.19463432 0.04231422
   2: 0.5  16 0.09908318 0.4460310 0.06286376 0.05462742
   3: 0.7  16 0.08374057 0.5277510 0.03820782 0.06463604
   4: 0.9  16 0.07385224 0.5984134 0.03026121 0.07329038
   5: 0.3  32 0.09045016 0.2443013 0.17003319 0.02992067
   6: 0.5  32 0.07006239 0.3153916 0.04250670 0.03862742
   7: 0.7  32 0.05921353 0.3731763 0.02563209 0.04570458
   8: 0.9  32 0.05222142 0.4231422 0.02037799 0.05182412
   9: 0.3  64 0.06395792 0.1727471 0.14072683 0.02115711
  10: 0.5  64 0.04954159 0.2230155 0.03286223 0.02731371
  11: 0.7  64 0.04187029 0.2638755 0.01946985 0.03231802
  12: 0.9  64 0.03692612 0.2992067 0.01475039 0.03664519
  13: 0.3 128 0.04522508 0.1221506 0.11012266 0.01496034
  14: 0.5 128 0.03503120 0.1576958 0.02260296 0.01931371
  15: 0.7 128 0.02960676 0.1865882 0.01317059 0.02285229
  16: 0.9 128 0.02611071 0.2115711 0.01036970 0.02591206
  </code></pre>