简体   繁体   English

如何在R中导入的jpeg上绘制数据?

[英]How do I draw data on an imported jpeg in R?

I have imported a jpeg and I would like to put data over the top of it (the picture is a habitat and I have data of movement of an animal living in the area). 我已经导入了一个jpeg,我想将数据放在它的顶部(图片是一个栖息地,我有生活在该地区的动物的移动数据)。 I am hoping to create lines that correspond to where the animal has been recorded. 我希望创建与动物记录位置相对应的线条。

So far, I have imported the image using 'readJPEG', and have visualized my data this way (img = my imported jpeg): 到目前为止,我已经使用'readJPEG'导入了图像,并以这种方式可视化我的数据(img =我导入的jpeg):

plot(1, type="n", xlim=c(100, 150), ylim=c(300, 350)) 
rasterImage(img,100, 300, 150, 350, interpolate = TRUE)  

Any help on how to plot data on top of this photo? 有关如何在此照片上绘制数据的任何帮助? I am hoping to simply use the coordinates already in place when I visualize the data (that is, the x and y tick labels indicated above). 我希望在我可视化数据时(即上面指出的x和y刻度标签)简单地使用已经存在的坐标。

Thank you! 谢谢!

You might find functions from the Bioconductor package EBImage helpful for working with your images, as they spare you the tedious task of setting the correct coordinates etc. Once you load the image with readImage and display it, you can use R base graphics functions such as points , lines , text and similar to add things on top. 您可能会发现Bioconductor包EBImage中的函数对于处理图像很有帮助,因为它们为您节省了设置正确坐标等繁琐的任务。一旦您使用readImage加载图像并display它,您就可以使用R基本图形功能,如pointslinestext和类似的东西在顶部添加。 Coordinates are set to image pixel coordinates with the origin (1,1) in the top left corner. 坐标设置为图像像素坐标与左上角的原点(1,1)。 The following example is taken from the package vignette . 以下示例取自包装插图

library("EBImage")

f = system.file("images", "sample.png", package="EBImage")
img = readImage(f)

display(img, method="raster")
text(x = 20, y = 20, label = "Parrots", adj = c(0,1), col = "orange", cex = 2)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM