this is my first question on SO, I hope someone can help me answer it.
I'm reading data from a csv with R with
data<-read.csv("/data.csv") and get something like:
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
Each group color may vary, they are assigned by a formula when the csv file is generated, but those are all the possible colors (the number of groups may also vary).
I've been trying to use ggplot() like so:
ggplot(data, aes(x = x, y = y, label = Group)) +
geom_point(aes(size = size, colour = Group), show.legend = TRUE) +
geom_text(size = 4) +
scale_size(range = c(5,15)) +
Everything is correct except for the colors
- small is drawn blue
- Medium is drawn red
- Other is drawn green
- Large is drawn yellow
I noticed the legend at the right orders the Groups alphabetically (Large, Medium, Other, Small), but the colors stay in the csv file order.
Here is a screenshot of the plot.
Can anyone tell me what's missing in my code to fix this? other approaches to achieve the same result are welcome.