Pick the color of choice (HSV or HCL or RGB) for i

2019-05-23 01:46发布

问题:

I have a dataset something like this

data <- read.table(text = "Me EE  PE   DE    TE    DEE   CE
1   1  1 4.5 2000  0.50 0.2547 0.69
2   1  2 2.4 3000    NA 0.5896 2.56
3   1  3 6.5 2345 15.24     NA 1.85
4   1  4  NA   NA 18.23 1.2594 2.06
5   2  1 2.6   NA 12.25 1.5943 2.34
6   2  2  NA 3145 10.25     NA   NA
7   2  3 2.7 4235    NA     NA 2.90
8   2  4  NA   NA  6.32 2.5990 3.18
9   3  1 3.5   NA  8.25 2.9339 3.46
10  3  2 3.8   NA    NA     NA   NA
11  3  3  NA   NA    NA 3.6037 1.58
12  3  4 4.4 4325    NA 3.9386 4.30
13  4  1 4.7   NA 15.24 4.2735 4.58
14  4  2  NA 4325  6.66     NA   NA
15  4  3 5.3   NA 25.20     NA   NA
16  4  4 5.6 3256    NA 5.2782 5.42
17  5  1  NA 4351 25.36 5.6131 5.70
18  5  2 6.2 2345    NA 5.9480   NA
19  5  3 6.5   NA 19.36     NA   NA
20  5  4  NA 4643 17.25 6.6178 6.54", header = T)

Dataset can be found in here. Dataset

I am trying to plot a ggplot2 point graph using

library(ggplot2)
ggplot(data,aes(x=EE,y=PE)) + geom_point( aes(color = factor(Me)))

and the plot is

I want to pick the color of my choice from the RGB or HSV or HCL and assign to individual factors or levels(Me) how can I do that?

How can I have proper colors assigned to unique(data$Me) values like c(red, blue, green, yellow, orange, black, brown, magenta, ...)

Thanks in advance.

回答1:

Add this to the plot

+ scale_colour_manual(values = c('red', 'green'))

You can also use hex codes.

+ scale_colour_manual(values = c('#FF0000', '#00FF00'))


标签: r ggplot2