Add text and line to `image ()` in the graphic

I created an image in R from two-dimensional data - x.

graphics::image(ifelse(drop(x)!=0, x, NA))

I would like to add text and line to the image.

I tried text(10, 10, "testing")and segments(5, 10, 20, 25), but neither text nor line were shown.

+4
source share
1 answer

As mentioned in @MrFlick, image()retells the values ​​in the range 0-1.

See below for an example:

#dummy data
set.seed(123)
x <- matrix(runif(100),nrow=10)

#plot
image(x)

#add text and a line
text(0.1,0.1,"text")
segments(0.5,0.1,0.2,0.25)

enter image description here

+1
source

All Articles