Add a legend of colors in image {graphics}

一曲冷凌霜 提交于 2019-12-10 18:41:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!