Assign point color depending on data.frame column value R
<p>this is my first question on SO, I hope someone can help me answer it.</p>

<p>I'm reading data from a csv with <code>R</code> with <code>data&lt;-read.csv("/data.csv")</code> and get something like:</p>

<pre><code>Group    x   y  size    Color
Medium   1   2  2000    yellow
Small   -1   2  1000    red
Large    2  -1  4000    green
Other   -1  -1  2500    blue
</code></pre>

<p>Each group color may vary, they are assigned by a formula when the <code>csv</code> file is generated, but those are all the possible colors (the number of groups may also vary).</p>

<p>I've been trying to use <code>ggplot()</code> like so:</p>

<pre><code>data&lt;-read.csv("data.csv")
xlim&lt;-max(c(abs(min(data$x)),abs(max(data$x))))
ylim&lt;-max(c(abs(min(data$y)),abs(max(data$y))))
data$Color&lt;-as.character(data$Color)
print(data)
ggplot(data, aes(x = x, y = y, label = Group)) +
geom_point(aes(size = size, colour = Group), show.legend = TRUE) +
scale_color_manual(values=c(data$Color)) +
geom_text(size = 4) +
scale_size(range = c(5,15)) +
scale_x_continuous(name="x", limits=c(xlim*-1-1,xlim+1))+
scale_y_continuous(name="y", limits=c(ylim*-1-1,ylim+1))+
theme_bw()
</code></pre>

<p>Everything is correct except for the colors</p>

<ul>
<li>small is drawn blue</li>
<li>Medium is drawn red</li>
<li>Other is drawn green</li>
<li>Large is drawn yellow</li>
</ul>

<p>I noticed the legend at the right orders the Groups alphabetically (Large, Medium, Other, Small), but the colors stay in the <code>csv</code> file order.</p>

<p>Here is a screenshot of the plot.</p>

<p><a href="https://i.stack.imgur.com/z2lMN.png" rel="noreferrer"><img src="https://i.stack.imgur.com/z2lMN.png" alt="enter image description here"></a></p>

<p>Can anyone tell me what's missing in my code to fix this? other approaches to achieve the same result are welcome.</p>