使用ggplot为各个图例值选择选择的颜色(HSV或HCL或RGB) [英] Pick the color of choice (HSV or HCL or RGB) for individual legend values using ggplot
本文介绍了使用ggplot为各个图例值选择选择的颜色(HSV或HCL或RGB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类似这样的数据集
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不适用1.85
4 1 4不适用18.23 1.2594 2.06
5 2 1 2.6不适用12.25 1.5943 2.34
6 2 2不适用3145 10.25不适用
7 2 3 2.7 4235不适用不适用2.90
8 2 4不适用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,标题= T)
D ataset可以在这里找到。 数据集
我试图用
ggplot2
点图>数据库(aes(x = EE,y = PE))+ geom_point(aes(color = factor(Me)))
pre>
并且图是
水平(Me)我该怎么做? 我怎样才能将适当的颜色分配给
unique(data $ Me)
值,如c(红色,蓝色,绿色,黄色,橙色,黑色,棕色,洋红色,...)
在此先感谢。
解决方案到情节
+ scale_colour_manual(values = c('red','gre en'))
您也可以使用十六进制代码
+ scale_colour_manual(values = c('#FF0000','#00FF00'))
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 usinglibrary(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 likec(red, blue, green, yellow, orange, black, brown, magenta, ...)
Thanks in advance.
解决方案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'))
这篇关于使用ggplot为各个图例值选择选择的颜色(HSV或HCL或RGB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文