title: Superimposing two or more subsets in same plot
body: <p>I'm trying to visualize a 3 level subset of my data in one figure for two different treatments.</p>
  
  <p>I want to visualize the distribution of age for only 1 year (2007), for only one item (tattoo), and for females and males separately.</p>
  
  <p>I am able to reduce my dataset to only females, only in 2007, and only for tattoos using:</p>
  
  <pre><code>with(data[(data$sex=="F") &amp; (data$yy=="2007") &amp; (data$item=="tattoo"),], plot(age, xlab="Age of Females", ylab="Frequency")) 
  </code></pre>
  
  <p>With this code, I am able to see a frequency distribution of my data.
  <a href="https://i.stack.imgur.com/rbUN1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rbUN1.jpg" alt="3 tier subset"></a></p>
  
  <p>But, I am unable, using that code, to do two things:</p>
  
  <ol>
  <li><p>visualize the data as a density plot</p></li>
  <li><p>superimpose the multiple tier subset for males</p></li>
  </ol>
  
  <p>The closest I've been able to come is using this code:</p>
  
  <pre><code>library(sm)
  sm.density.compare(age, sex, xlab="Age (years)")
  legend(50,0.12, c("Female","Male"), col=c("red", "green"), pch=c(16,16), title="Sex", box.lty=0)
  </code></pre>
  
  <p>It gives this figure:
  <a href="https://i.stack.imgur.com/9OCWw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9OCWw.jpg" alt="Density plot"></a></p>
  
  <p>But, with this code, I am unable to get the data to be restricted to the year 2007 and only tattoos.</p>
  
  <p>My question is two fold: </p>
  
  <ol>
  <li><p>Is it possible to superimpose the male data (for 2007 and tattoos) on the female frequency data?</p></li>
  <li><p>How can I restrict the density data to only 2007 and tattoos?</p></li>
  </ol>
  
  <p>I have made a subset of my data available <a href="https://figshare.com/s/ace5b44bc12394a7c46d" rel="nofollow noreferrer">here</a>. </p>
  
  <p>UPDATE: For the frequency histogram, I am trying to visualize the data with the bars for female and male adjacent to each other for each bin.</p>