R: add title to wordcloud graphics / png

后端 未结 2 1723
渐次进展
渐次进展 2021-02-13 16:22

I have some working R code that generates a tag cloud from a term-document matrix.

Now I want to create a whole bunch of tag clouds from many documents, and to inspect

2条回答
  •  粉色の甜心
    2021-02-13 17:19

    One idea is to import the images , and save again them using grid.raster, and add the titile using grid.text. For example:

    ll <- list.files(patt='*.png')
    library(png)
    library(grid)
    imgs <- lapply(ll,function(x){
      img <- as.raster(readPNG(x))
      ## get the file name
      x.name <- gsub('(.*).png','\\1',x)
      ## new device for new image version
      png(file =paste(x.name,'_modified','.png',sep=''))
      grid.raster(img)
      ## here I add title
      grid.text(label = x.name,x=0.5,y=0.9,gp=gpar(cex=2))
      dev.off()
    
    })
    

提交回复
热议问题