在 R 中创建具有与绘图相同的 RGB 颜色值的图例?
我在 R 中创建了一个具有特定 RGB 颜色值的简单散点图,如下所示:
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))
我想在上面的代码中使用相同的颜色值来生成图形图例。我使用的代码看起来像这样,但我似乎无法弄清楚如何匹配图点的颜色。
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))
有人可以帮忙吗?我的传说有什么问题吗?谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是您将 R 颜色关键字“black”与十六进制颜色键连接起来。像这样的东西应该有效:
The problem is that you are concatenating an R color keyword, "black", with hexadecimal color keys. Something like this should work:
这对我有用:
请注意,您需要指定一个 col= 向量、标签的大小,并且还必须在那里有一个 pch= 。或者,您可以执行 fill=[颜色向量] 来绘制填充框。
This works for me:
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.