title: Conditional labeling in ggplot2 using geom_text and subsetting
body: <p>I'm new to the community and I'm posting this after giving multiple attempts at this while searching the solutions mentioned online. However, I haven't been able to resolve it.</p>
  
  <p>The following code</p>
  
  <pre><code>dat&lt;-read.csv("Harvard tutorial/Rgraphics/dataSets/EconomistData.csv")
  g &lt;- ggplot(dat, aes(dat$CPI, dat$HDI))
  
  g1 &lt;- g + theme_bw() + geom_smooth(method = "lm", formula = y ~log(x), se = FALSE, color = "Red", linetype = 1, weight = 3) +
    geom_point(aes(color = Region), size = 4, fill = 4, alpha = 1/2, shape = 1) +
    scale_x_continuous(name = "Corruption Perception Index", breaks = NULL) +
    scale_y_continuous(name = "Human Development Index") +
    scale_color_manual(name = "Region of the world", values = c("#24576D", "#099DD7", "#28AADC", "#248E84", "#F2583F", "#96503F")) + 
    theme(axis.text.x = element_text(angle = 90, size = 15))
  </code></pre>
  
  <p>This gives me the following result:</p>
  
  <p><a href="https://i.stack.imgur.com/USHLf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/USHLf.png" alt="enter image description here"></a></p>
  
  <p>However, when I add the following lines to the code</p>
  
  <pre><code>pointsToLabel &lt;- c("Russia", "Venezuela", "Iraq", "Myanmar", "Sudan",
                     "Afghanistan", "Congo", "Greece", "Argentina", "Brazil",
                     "India", "Italy", "China", "South Africa", "Spane",
                     "Botswana", "Cape Verde", "Bhutan", "Rwanda", "France",
                     "United States", "Germany", "Britain", "Barbados", "Norway", "Japan",
                     "New Zealand", "Singapore")
  
  g2 &lt;- g1 + geom_text(aes(dat$CPI, dat$HDI, label = dat$Country), data = subset(x = dat,subset =  Country %in% pointsToLabel))
  </code></pre>
  
  <p>I get the following error</p>
  
  <p><em>Error: Aesthetics must be either length 1 or the same as the data (27): x, y, label</em></p>
  
  <p>Can someone help me with this?</p>
  
  <p>The data is sourced from <a href="http://tutorials.iq.harvard.edu/R/Rgraphics.zip" rel="noreferrer">Harvard Tutorial on GGPLOT2</a></p>
  
  <p>For your info, the structure of the dataset is as follows</p>
  
  <pre><code>'data.frame':   173 obs. of  6 variables:
   $ X       : int  1 2 3 4 5 6 7 8 9 10 ...
   $ Country : Factor w/ 173 levels "Afghanistan",..: 1 2 3 4 5 6 7 8 9 10 ...
   $ HDI.Rank: int  172 70 96 148 45 86 2 19 91 53 ...
   $ HDI     : num  0.398 0.739 0.698 0.486 0.797 0.716 0.929 0.885 0.7 0.771 ...
   $ CPI     : num  1.5 3.1 2.9 2 3 2.6 8.8 7.8 2.4 7.3 ...
   $ Region  : Factor w/ 6 levels "Americas","Asia Pacific",..: 2 3 5 6 1 3 2 4 3 1 ...
  </code></pre>