问题
In this example, I have an image with colors and I wonder if we can add a legend of colors. for example : points with z
in [8:10]
have color red and so on.
x=runif(500,0,5)
y=runif(500,0,5)
z=floor(runif(500, 1,10))
xyz=data.frame(x,y,z)
library(MBA)
mba.int <- mba.surf(xyz, 300, 300, extend=T)$xyz.est
image(mba.int, xaxs="i", yaxs="i")
Thank you.

回答1:
Thanks to @user20650, the answer is :
fields::image.plot(mba.int, col = heat.colors(12))

回答2:
Something along the lines. Expand the logic and numbers to suit your needs.
col1 = ifelse(z < 4 , "red", ifelse(z >=4 , "green", "black"))
image(mba.int, xaxs="i", yaxs="i", col= col1)
来源:https://stackoverflow.com/questions/28301514/add-a-legend-of-colors-in-image-graphics