title: Make Frequency Histogram for Factor Variables
body: <p>I am very new to R, so I apologize for such a basic question. I spent an hour googling this issue, but couldn't find a solution.</p>
  
  <p>Say I have some categorical data in my data set about common pet types. I input it as a character vector in R that contains the names of different types of animals. I created it like this: </p>
  
  <pre><code>animals &lt;- c("cat", "dog",  "dog", "dog", "dog", "dog", "dog", "dog", "cat", "cat", "bird")
  </code></pre>
  
  <p>I turn it into a factor for use with other vectors in my data frame:</p>
  
  <pre><code>animalFactor &lt;- as.factor(animals)
  </code></pre>
  
  <p>I now want to create a histogram that shows the frequency of each variable on the y-axis, the name of each factor on the x-axis, and contains one bar for each factor. I attempt this code:</p>
  
  <pre><code>hist(table(animalFactor), freq=TRUE, xlab = levels(animalFactor), ylab = "Frequencies")
  </code></pre>
  
  <p>The output is absolutely nothing like I'd expect. Labeling problems aside, I can't seem to figure out how to create a simple frequency histogram by category. </p>