3

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.enter image description here

Math
  • 1,274
  • 3
  • 14
  • 32
  • 3
    http://stackoverflow.com/questions/28222375/positioning-legend-on-plot-divided-by-parmfrow-in-r/28223329#28223329 might help. (or use`fields::image.plot(mba.int, col = heat.colors(12))`) – user20650 Feb 03 '15 at 14:51
  • 1
    Good stuff. Please feel free to write it up as an answer [and accept it ;)] – user20650 Feb 03 '15 at 15:03

2 Answers2

3

Thanks to @user20650, the answer is :

fields::image.plot(mba.int, col = heat.colors(12))

enter image description here

Math
  • 1,274
  • 3
  • 14
  • 32
0

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)
Alexey Ferapontov
  • 5,029
  • 4
  • 22
  • 39
  • Actually this could change the results, I want to keep this image but adding some legends. – Math Feb 03 '15 at 14:45