在R中创建具有与图相同的RGB颜色值的图例? [英] Create legend in R with identical RGB color values as plot?
问题描述
我已经在R中创建了一个具有以下特定RGB颜色值的简单散点图:
I've created a simple scatter plot in R with specific RGB color values like this:
plot(shuffled, p_val, pch=19, col="black", xlim=c(0,100), ylim=c(0,1))
points(ri, p_val, pch=19, col=rgb(96,123,139, 50, maxColorValue=255),
xlim=c(0,100), ylim=c(0,1))
points(somo, p_val, pch=19, col=rgb(225,64,5, 50, maxColorValue=255),
xlim=c(0,100), ylim=c(0,1))
我想在上面的代码中使用相同的颜色值来生成图例.我正在使用的代码看起来像这样,但是我似乎无法弄清楚如何匹配图形点的颜色.
I would like to use the same color values in the code above to generate a figure legend. The code I am using looks like this, but I can't seem to figure out how to match the colors of the graph points.
legend("topright", c("Shuffled", "Riffled", "Somosome"), cex=1.0, bty="n",
c("black",col=rgb(96,123,139, 50, maxColorValue=255),col=rgb(225,64,5, 50, maxColorValue=255))
有人可以帮忙吗?我的传说怎么了?谢谢!
Can any one help? What is wrong with my legend? Thanks!
推荐答案
这对我有用:
plot(1:3,
col=c("black",rgb(96,123,139, 50, maxColorValue=255),
rgb(225,64,5, 50,maxColorValue=255)),pch=19)
legend("topright", c("Shuffled", "Riffled", "Somosome"), cex=1.0, bty="n",
col=c("black",rgb(96,123,139, 50, maxColorValue=255),
rgb(225,64,5, 50, maxColorValue=255)),pch=19)
请注意,您需要指定一个向量col =,即标签的大小,并且还必须在其中也有一个pch =.或者,您可以执行fill = [颜色向量]来绘制填充框.
Note you need to specify one vector of col=, the size of your labels, and you also have to have a pch= in there too. Alternatively you can do fill=[vector of colours] to draw filled boxes.
这篇关于在R中创建具有与图相同的RGB颜色值的图例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!