Ziyuan
Ziyuan

Reputation: 4558

How to use custom point style in plot?

I am doing a dimensional reduction experiment, where a set of faces will be places onto a X-Y plane. I want to show the real face at each point in the plot (Example: Figure 10 at the page 476). Can I do this in R? Thank you.

enter image description here

Upvotes: 9

Views: 1665

Answers (1)

thelatemail
thelatemail

Reputation: 93813

You will probably need some add-on packages like png and raster to achieve this. So first up, make sure you have the packages loaded.

library(png)
library(raster)

Now, get an image (an awesome squiggle I made in ms paint - saved as spotimg.png):

enter image description here

Load the image into R and plot it:

pngimg <- readPNG("spotimg.png")
plot(NA,xlim=c(0,10),ylim=c(0,10))
rasterImage(pngimg,4.5,4.5,5,5)

The last 4 inputs to the rasterImage call give the coordinates of the image's boundary in the format xleft, ybottom, xright, ytop

And bingo, there's your image plotted where you specified.

enter image description here

Upvotes: 8

Related Questions