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!
This works for me:
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With