title: Coloring the points by category in R
body: <p>I am creating a scatter plot in R using the following code:</p>
  
  <pre><code>plot(df_prob1$x1, df_prob1$x2, pch = df_prob1$y)
  </code></pre>
  
  <p>I get the following plot:</p>
  
  <p><a href="https://i.stack.imgur.com/BGJNn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BGJNn.png" alt="enter image description here"></a></p>
  
  <p>As seen in the above plot there are two categories, one represented by a square and the other by circle. I want these two categories to have different colors as well.</p>
  
  <p>I did try using the following code:</p>
  
  <pre><code>plot(df_prob1$x1, df_prob1$x2, pch = df_prob1$y, col = c("red", "blue"))
  </code></pre>
  
  <p>And I get the following plot:</p>
  
  <p><a href="https://i.stack.imgur.com/1LvXo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1LvXo.png" alt="enter image description here"></a></p>
  
  <p>However, it is randomly coloring points and not taking the categories into consideration.</p>
  
  <p>I also did trying passing the variable as value for col as such:</p>
  
  <pre><code>plot(df_prob1$x1, df_prob1$x2, pch = df_prob1$y, col = df_prob1$y)
  </code></pre>
  
  <p>But this didn't give a proper plot.</p>