Adding a picture to plot in R

后端 未结 3 1457
轻奢々
轻奢々 2020-12-14 21:40

I\'m trying to add a picture (jpeg,png doesn\'t care) to a plot which is defined by the layout function. For example:

a<-c(1,2,3,4,5)

b<-c(2,4,8,16,32         


        
3条回答
  •  半阙折子戏
    2020-12-14 22:07

    You need to read your png or jpeg file through the png and jpeg packages. Then, with the rasterImage function you can draw the image on a plot. Say that your file is myfile.jpeg, you can try this:

    require(jpeg)
    img<-readJPEG("myfile.jpeg")
    #now open a plot window with coordinates
    plot(1:10,ty="n")
    #specify the position of the image through bottom-left and top-right coords
    rasterImage(img,2,2,4,4)
    

    The above code will draw the image between the (2,2) and (4,4) points.

提交回复
热议问题