在图形中的"image()"中添加文本和行 [英] Add text and line to an `image()` in graphics

查看:77
本文介绍了在图形中的"image()"中添加文本和行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从二维数据-x中生成了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.

我尝试了text(10, 10, "testing")segments(5, 10, 20, 25),但是文本和行均未显示.

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

推荐答案

如@MrFlick所述,image()将值重新缩放为0-1范围.

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

请参见以下示例:

#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)

这篇关于在图形中的"image()"中添加文本和行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆