2

I'm relatively new to R and trying to create multiple geographic maps. I already managed to make one map and customise it the way it should be. However, I need to make 100+ similar maps with only one difference: the input of the thematic color. My input are two shapefiles (postal code and province in the Netherlands) and a csv-file with corresponding postal codes and several columns with paercentages to fill the areas.

example of part of the dataset (in real 100+ columns with percentages):

example of part of the dataset (in real 100+ columns with percentages)

Below my R code which works for making one map:

R code for one map

This map is created:

map created

I've been experimenting a while with all kinds of loops, but I guess my R knowledge is not sufficient. What I want is two things:

1) Make 'K1' iterate to all columns in my dataset, and 2) Save all the maps it creates with the same name (K1, K2 etc.) in it.

If you need more information, just let me know!

TontonVelu
  • 471
  • 2
  • 8
  • 21
David
  • 31
  • 5
  • 1
    Hi, welcome to stackoverflow. Pleas do not post image of code, but the code itself. http://idownvotedbecau.se/imageofcode – TontonVelu Dec 13 '19 at 08:09

1 Answers1

0

You didn't give us enough code but I will try to give an answer with another dataset.

I take the data example of tmap package.

library(tmap)
data("World")

filepath <- "D:/Utilsateur/Documents/"
colors <- paste("K", 1: 7, sep = "")
for(K in 1:length(colors)){
  kaart <- tm_shape(World) +
    tm_polygons("HPI")
  # you may change tm_fill = "K1" by tm_fill = colors[K]
  tmap_save(kaart, filename = paste(filepath, colors[K], ".png", sep = ""))
}

I hope it helps.

Rémi Coulaud
  • 1,684
  • 1
  • 8
  • 19