Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add text and line to an `image()` in graphics

Tags:

plot

r

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

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

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

I attempted text(10, 10, "testing") and segments(5, 10, 20, 25), but neither the text nor the line was displayed.

like image 516
TTZ Avatar asked May 14 '15 20:05

TTZ


1 Answers

As @MrFlick mentioned, image() rescales values to the 0-1 range.

See below 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

like image 150
zx8754 Avatar answered Oct 14 '22 10:10

zx8754