title: How do you remove NA's in geom_bar when plotting data subsets?
body: <p>this is related to the question <a href="https://stackoverflow.com/questions/11403104/remove-unused-factor-levels-from-a-ggplot-bar-plot?lq=1">here</a>, but the proposed solutions don't work in my case. </p>
  
  <p>I've already posted a question regarding my large <code>data.frame</code> <a href="https://stackoverflow.com/questions/22855197/how-do-you-get-geom-map-to-show-all-parts-of-a-map/22875922?noredirect=1#comment34951335_22875922">here</a>, but if you just want to download it (>2000 rows) please do so via <a href="https://www.dropbox.com/s/87tnryu9zzf541t/ARCTP53_SOExample.txt?n=9895686" rel="nofollow noreferrer">this link</a>.</p>
  
  <p>So the <strong>following code</strong> is used to create a simple <code>geom_bar</code>barplot in <code>ggplot2</code></p>
  
  <pre><code>gghist&lt;-ggplot(ARCTP53_SOExample[ARCTP53_SoExample$Structural_motif=="NDBL/beta-sheets",],
  aes(x=p53_IHC))
  gghist+geom_bar()
  </code></pre>
  
  <p>This produces <strong>this plot</strong>:
  <img src="https://i.stack.imgur.com/t9oGq.png" alt="A barplot with lots of &quot;NA&#39;s&quot;"></p>
  
  <p>As you can see, the NA's are plotted as well. I've tried various options to remove the NA's including the <strong><em>following</em></strong>: </p>
  
  <pre><code>gghist&lt;-ggplot(ARCTP53_SOExample[ARCTP53_SOExample$Structural_motif=="NDBL/beta-sheets",], aes(x=p53_IHC), drop=TRUE)
  gghist+geom_bar()
  gghist&lt;-ggplot(ARCTP53_SOExample[ARCTP53_SOExample$Structural_motif=="NDBL/beta-sheets",], aes(x=p53_IHC), na.rm=TRUE)
  gghist+geom_bar()
  gghist&lt;-ggplot(ARCTP53_SOExample[ARCTP53_SOExample$Structural_motif=="NDBL/beta-sheets",], aes(x=p53_IHC, na.rm=TRUE))
  gghist+geom_bar()
  gghist&lt;-ggplot(ARCTP53_SOExample[ARCTP53_SOExample$Structural_motif=="NDBL/beta-sheets",], aes(x=factor(p53_IHC), na.rm=TRUE))
  gghist+geom_bar()
   gghist&lt;-ggplot(ARCTP53_SOExample[ARCTP53_SOExample$Structural_motif=="NDBL/beta-sheets",], aes(x=factor(p53_IHC))
      gghist+geom_bar(na.rm=TRUE)
  </code></pre>
  
  <p>And then I tried <strong>this</strong>: </p>
  
  <pre><code>gghist_2&lt;-ggplot(na.omit(ARCTP53_SOExample[ARCTP53_EsoMutClean$Structural_motif=="NDBL/beta-sheets",]), aes(x=p53_IHC))
  gghist_2+geom_bar()
  </code></pre>
  
  <p>Which gives me <strong><em>this error</em></strong>: </p>
  
  <pre><code>Error in as.environment(where) : 'where' is missing
  </code></pre>
  
  <p>Further, I tried <strong><em>this</em></strong>, which gives me the following <strong>errors</strong></p>
  
  <pre><code>datasub&lt;-ARCTP53_SOExample[!is.na(ARCTP53_SOExample)]
  gghist_3&lt;-ggplot(datasub[datasub$Structural_motif=="NDBL/beta-sheets",])
  Error in datasub$Structural_motif : 
    $ operator is invalid for atomic vectors
  </code></pre>
  
  <p>And this code doesn't work either: </p>
  
  <pre><code>gghist_3&lt;-ggplot(datasub, aes(x=p53_IHC))
  Error: ggplot2 doesn't know how to deal with data of class character
  </code></pre>
  
  <p>So, does anyone know an easy solution to this? The <code>data.frame</code> is big and inherently has a lot of missing data depending on which column I'm looking at, but not all missing data is missing across all rows, so deleting any row that has a single "NA" in it, would be defeating the point. </p>
  
  <p>Help is much appreciated. </p>
  
  <p>Kind regards, </p>
  
  <p>Oliver</p>
  
  <p><strong>EDIT</strong> Following Daniel's comments below, this what I get following the code <em>below</em>. As you can see the problem is still not solved. Sorry.</p>
  
  <pre><code>gghist&lt;-ggplot(ARCTP53_SOExample[ARCTP53_SOExample$Structural_motif=="NDBL/beta-sheets" &amp; is.na(ARCTP53_SOExample$p53_IHC) == F,], aes(x=p53_IHC))
  gghist+geom_bar()
  </code></pre>
  
  <p>UPDATE: Re-Ran the code and for some reason it works now. Got the plot below: </p>
  
  <p><img src="https://i.stack.imgur.com/4zVDA.png" alt="It works"></p>
  
  <p><img src="https://i.stack.imgur.com/o5q8y.png" alt="NAs reduced but still there"></p>