title: How do I group different elements of a csv file into the same group?
body: <p>I'm making a grouped bar plot. Here is my code:</p>
  <pre><code>imagedata &lt;- read.csv(file = &quot;C:\\Users\\Owner\\Documents\\firstactivity\\data\\synthea_sample_data_csv_apr2020\\csv\\imaging_studies.csv&quot;)
  bodysite &lt;- imagedata$BODYSITE_DESCRIPTION
  mod &lt;- imagedata$MODALITY_CODE
  bodysite_case &lt;- tolower(bodysite) #so that &quot;thoracic&quot; and &quot;Thoracic&quot; will be categorized together
  barplot(table(mod, bodysite_case), main = &quot;Imaging Studies&quot;, ylab = &quot;Frequency&quot;, names.arg=c(&quot;Ankle&quot;,&quot;Arm&quot;,&quot;Chest&quot;,&quot;Clavicle&quot;,&quot;Knee&quot;,&quot;Pelvis&quot;,&quot;RUQ&quot;,&quot;Thoracic&quot;,&quot;Thoracic structure&quot;,&quot;Thoracic body structure&quot;,&quot;Wrist&quot;),col = c(&quot;red&quot;, &quot;blue&quot;, &quot;green&quot;, &quot;yellow&quot;), legend.text = colnames(table),las=2, beside=TRUE)
  title(xlab = &quot;Body Site&quot;, line = 4, adj=0)
  legend(&quot;top&quot;, fill=c(&quot;red&quot;, &quot;blue&quot;, &quot;green&quot;, &quot;yellow&quot;), c(&quot;CR&quot;, &quot;CT&quot;, &quot;DX&quot;, &quot;US&quot;))
  </code></pre>
  <p>And here is my current produced bar plot:
  <a href="https://i.stack.imgur.com/btKfj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/btKfj.png" alt="current bar plot" /></a></p>
  <p>How do I make it so that I can combine the thoracic groups (which are the 8th, 9th and 10th categories from left to right) into one group, since they have very similar names?</p>
  <p>Here's my data sample with dput:</p>
  <pre><code>structure(c(0L, 0L, 32L, 0L, 0L, 0L, 48L, 0L, 0L, 0L, 19L, 0L, 
  0L, 0L, 31L, 0L, 0L, 0L, 29L, 0L, 0L, 0L, 11L, 0L, 0L, 0L, 0L, 
  1L, 0L, 0L, 0L, 172L, 0L, 0L, 61L, 0L, 76L, 328L, 0L, 0L, 0L, 
  0L, 47L, 0L), .Dim = c(4L, 11L), .Dimnames = list(mod = c(&quot;CR&quot;, 
  &quot;CT&quot;, &quot;DX&quot;, &quot;US&quot;), bodysite_case = c(&quot;ankle&quot;, &quot;arm&quot;, &quot;chest&quot;, 
  &quot;clavicle&quot;, &quot;knee&quot;, &quot;pelvis&quot;, &quot;structure of right upper quadrant of abdomen&quot;, 
  &quot;thoracic&quot;, &quot;thoracic structure&quot;, &quot;thoracic structure (body structure)&quot;, 
  &quot;wrist&quot;)), class = &quot;table&quot;)
  </code></pre>