R: How to create multiple maps (rworldmap) using apply?

后端 未结 1 859
清歌不尽
清歌不尽 2021-01-28 06:04

I want to create multiple maps (similar to this example) using the apply family. Here a small sample of my code (~200 rows x 150 cols). (UN and ISO3 are codes for rworldmap):

相关标签:
1条回答
  • 2021-01-28 07:04

    You are close.

    Add this to save one plot per column.

    #put column names to plot in a vector
    col_names <- names(df)[1:6]
    
    
    lapply(col_names, function(x) {
      #opens device to store pdf
      pdf(paste0(x,'.pdf'))
      #plots map
      mapCountryData(spdf, nameColumnToPlot=x)
      #closes created pdf 
      dev.off()
    })
    
    0 讨论(0)
提交回复
热议问题