Placing Custom Images in a R-Plot

 

I would like to add small svg or preferably png images (displaying chemical structures) into a generic x-y plotting generated with the"Table R-view" node .

Doing the plot itself is no issue, but I'm unable to add my images into this plot. The resulting plot should look similar as the one you see in this discussion forum.

http://stackoverflow.com/questions/4860417/placing-custom-images-in-a-plot-window-as-custom-data-markers-or-to-annotate-t

In this link they explain how to place png files into a R-plot. Any idea how I could this within KNIME?

On one side the KNIME column with the png file does not occur in the list of selectable columns in the "Table R-view" node. So how to import ? Would rasterImage then work for multiple rows?

On the other side how can I do this with svg files? Here the advantage is that the "svg" column is selectable in the "Table R-view" node, but I'm unable to place the images into the plot. I tried add.image and image.plot, but I get the error: Execution of R script failed: Function cannot be found.

Regards,

Andreas

 

 

 

 

You could use the "create temp dir" node and "image column writer" node to save the images to a temporary directory, and then access them via their paths in the R View

Steve

And specifically in ggplot2 v0.9 and later, I believe the annotation_raster() function will let you place an image on your plot wherever needed.

Thanks for your help. I still struggle though I tried various possibilitites. Somehow the best I got was using the rasterImage() function, but I still could not manage to read back the png files.

I attach a very simple workflow with some made up data . If any one could get me the correct coding I would very much appreciate .

Andreas

Here is the mentioned file.

Hiyas, 

Have a look at the attached workflow and let me know if this gets you there.  The solution uses ggplot2 and loop to append the structures from a temporary folder. 

Regards,

Aaron

 

ps - the code for those interested:

 

library(png)

library(ggplot2)

x = knime.in$"x"
y = knime.in$"y"

plot = qplot(x,y) + geom_point()

n = length(knime.in$"Location")

for (i in 1:(n)) {
    path = as.character(knime.in$"Location"[(i)])
    img = readPNG(path)
    xmin = x[i]-0.5
    xmax = x[i]+0.5
    ymin = y[i]-1
    ymax = y[i]+1
    plot = plot + annotation_raster(img, xmin, xmax, ymin, ymax)
}

x_scale = scale_x_continuous(limits = c(min(x)-1, max(x)+1))
y_scale = scale_y_continuous(limits = c(min(y)-1, max(y)+1))

plot + x_scale + y_scale

Hi Aaron,

this works fine. Many thanks for your help.

Using your workflow I noticed that there are also R Interactive nodes available which provide even more functionality:-)

Interestingly these nodes also support the PNG image as a column. In your workflow you have filtered this column out out just sending to the R node). Given this possibility I wonder if it is necessary to use the work-around to export and re-import the png files? I did not get it working, but it might be easy for you or someelse.... If possible I would be curious for the code.

@ other users: I had to install the png library into my R installation to get the last R view node working properly. To do so search for the RGui.exe within the KNIME installation and follow the menu installation.