简体   繁体   中英

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). 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):

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

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. Coordinates are set to image pixel coordinates with the origin (1,1) in the top left corner. 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)

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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