1
+ # libraries used
2
+ library(tanaka )
3
+ library(raster )
4
+ library(sf )
5
+ library(cartography )
6
+
7
+ # loading the geographics files
8
+ mask_file <- sf :: st_read(" rawdata/shapes/haiti_shape.shp" )
9
+
10
+ raster_file <- raster :: raster(" rawdata/rasters/haiti_srtm_wgs_18N.tif" )
11
+
12
+ resample_raster <- raster :: aggregate(raster_file , fact = 50 , fun = mean ) # resampling the raster file
13
+
14
+
15
+ png(" output/plots/haiti_TanakaContour_50.png" , # creating the map file
16
+ width = 1200 ,
17
+ height = 850 ,
18
+ pointsize = 6 ,
19
+ res = 300
20
+ )
21
+ par(mar = c(0 , 0 , 1 , 0 )) # setting the margin
22
+
23
+ # tanaka contour
24
+ tanaka :: tanaka(
25
+ resample_raster ,
26
+ breaks = c(seq(0 , 2500 , 250 ), 2680 ),
27
+ legend.pos = " n" ,
28
+ legend.title = " Elevation\n (meters)" ,
29
+ col = carto.pal(" harmo.pal" , length(c(
30
+ seq(0 , 2500 , 250 ), 2680
31
+ ))),
32
+ light = " #ffffff70" ,
33
+ dark = " #00000090" ,
34
+ mask = mask_file
35
+ )
36
+ # legend configuration
37
+ cartography :: legendChoro(
38
+ pos = " topleft" ,
39
+ title.txt = " Élévation\n (mètres)" ,
40
+ title.cex = 1 ,
41
+ breaks = c(seq(0 , 2500 , 250 ), 2680 ),
42
+ col = carto.pal(" harmo.pal" , length(c(
43
+ seq(0 , 2500 , 250 ), 2680
44
+ ))),
45
+ nodata = FALSE ,
46
+ nodata.txt = " No Data" ,
47
+ frame = F
48
+ )
49
+ # layout part
50
+ cartography :: layoutLayer(
51
+ title = " \n\n Haiti (Tanaka Contours)" ,
52
+ tabtitle = TRUE ,
53
+ frame = TRUE ,
54
+ horiz = TRUE ,
55
+ col = " black" ,
56
+ author = " @TRedgi, 2019" ,
57
+ sources = " Sources: NASA SRTM Version 3.0" ,
58
+ north = TRUE ,
59
+ theme = NULL ,
60
+ extent = NULL ,
61
+ scale = 50
62
+ )
63
+
64
+ dev.off()
0 commit comments