1

I have dataset (vg) with observations uniquely identified with an image's filename. I have a folder with these images, named the same way (e.g., 001.jpg ... 501.jpg). I would like to graph my data using the actual images as the "geom" in ggplot2.

I was able to figure out how to plot an image thanks to this answer. However, I am left with two issues: (1) plotting many images using a loop and (2) plotting the images on the graph based on the data in my dataset. I am presently concerned with reading the images into some sort of list or data frame. Here is what I have tried:

imgdir = "c:/mydir"
setwd(imgdir)
l = length(dir())
img <- graph.data.frame()
for (i in l) {
  load = readJPEG(dir()[i], TRUE) %>%
    rasterGrob(interpolate=TRUE)
  img[1:length(load)] = load
  img[1:length(load)] = dir()[i]
}

It's cute but it obviously does not work. Frankly, I do not understand how the object this creates functions. Ideally, I would have a dataframe with the filename and raster (is that what it is?), or even just load the image into my dataset. Then I would have to figure out how to give ggplot 700+ images to plot!

I am rather new to R and recognize this may not be possible the way I envision it. Thank you for your patience.

Community
  • 1
  • 1
reddy
  • 11
  • 2

0 Answers0