2017-01-23 175 views
6

在ggplot2中,我们可以选择按名称或十六进制代码设置颜色。有没有办法以相同的方式使用rgb值?我搜索了文档,但快速回答似乎是'不'。 (我想使用rgb的原因是我有一些颜色,我将用于一些情节,我有他们所有的RGB格式。我可以从像here这样的地方得到十六进制,但它会很好,如果我可以只输入值直入ggplot()rgb()with ggplot2 in R

+4

什么功能['rgb'(HTTPS://统计。 ethz.ch/R-manual/R-devel/library/grDevices/html/rgb.html)? – bouncyball

+1

'qplot(x = 1,fill = I(rgb(0.1,0.8,0.5)))' – Axeman

+0

好!不知道这个功能,谢谢,Axeman&bouncyball。 – RobertMc

回答

8

您可以使用函数RGB到分数RGB值转换为十六进制

rgb(0.1,0.2,0.3) 
[1] "#1A334D" 
+3

太好了,我用这个目录ectly在plot函数中,但是如果你没有你的RGB颜色的分数,它需要'maxColorValue'参数:'scale_colour_manual(values = c(rgb(207,31,46,maxColorValue = 255)),“#ffda85 “))' – RobertMc