title: Subsetting Data in R to Plot Constrained Data
body: <p>I have a data set (in R) called data which contains information about petrol and one of the columns is “Site_Brand” which contains the name of the petrol station (e.g. 7 Eleven)</p>
  
  <p>I want to subset this data (or constrain it) so that only rows with “7 Eleven”, “Caltex” or “Costco” are retained.</p>
  
  <p>I have tried using 
  myvars &lt;- c(“7 Eleven", "Caltex", "Costco")
  newdata &lt;- data[myvars]
  However, when I plot this in a graph, the data just doesn't appear at all.
  Thanks in advance!</p>
  
  <p>Here's the most recent code I have tried ...</p>
  
  <pre><code># using subset function
  data &lt;- subset(data, data$Site_Brand == "7 Eleven" | data$Site_Brand == "Caltex",)
  
  newData &lt;- data[c("7 Eleven", "Costco", "Caltex"), ]
  
  # Grouped Bar Plot
  counts &lt;- table(newData$Site_Brand, newData$Fuel_Type)
  barplot(counts, main="Car Distribution by Gears and VS",
    xlab="Number of Gears", col=c("darkblue","red"),
    legend = rownames(counts), beside=TRUE)
  </code></pre>