I.何をする?

次にしたがいtmapの使い方を学びます。

https://cran.r-project.org/web/packages/tmap/vignettes/tmap-getstarted.html

II.サンプル・データ

次でサンプル・データを呼び出すことができます。“World”はsf packageのもので、各国の人口やGDPなど基本的な情報が含まれています。データ・フレームのです。

library(tmap)
data("World")
head(World)
## Simple feature collection with 6 features and 15 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -6237303 ymin: -6576291 xmax: 6474206 ymax: 5306915
## CRS:           +proj=eck4 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
##   iso_a3                 name           sovereignt     continent
## 1    AFG          Afghanistan          Afghanistan          Asia
## 2    AGO               Angola               Angola        Africa
## 3    ALB              Albania              Albania        Europe
## 4    ARE United Arab Emirates United Arab Emirates          Asia
## 5    ARG            Argentina            Argentina South America
## 6    ARM              Armenia              Armenia          Asia
##                area  pop_est pop_est_dens                   economy
## 1  652860.00 [km^2] 28400000     43.50090 7. Least developed region
## 2 1246700.00 [km^2] 12799293     10.26654 7. Least developed region
## 3   27400.00 [km^2]  3639453    132.82675      6. Developing region
## 4   71252.17 [km^2]  4798491     67.34519      6. Developing region
## 5 2736690.00 [km^2] 40913584     14.95003   5. Emerging region: G20
## 6   28470.00 [km^2]  2967004    104.21510      6. Developing region
##                income_grp gdp_cap_est life_exp well_being footprint inequality
## 1           5. Low income    784.1549   59.668        3.8      0.79  0.4265574
## 2  3. Upper middle income   8617.6635       NA         NA        NA         NA
## 3  4. Lower middle income   5992.6588   77.347        5.5      2.21  0.1651337
## 4 2. High income: nonOECD  38407.9078       NA         NA        NA         NA
## 5  3. Upper middle income  14027.1261   75.927        6.5      3.14  0.1642383
## 6  4. Lower middle income   6326.2469   74.446        4.3      2.23  0.2166481
##        HPI                       geometry
## 1 20.22535 MULTIPOLYGON (((5310471 451...
## 2       NA MULTIPOLYGON (((1531585 -77...
## 3 36.76687 MULTIPOLYGON (((1729835 521...
## 4       NA MULTIPOLYGON (((4675864 313...
## 5 35.19024 MULTIPOLYGON (((-5017766 -6...
## 6 25.66642 MULTIPOLYGON (((3677241 513...

列名を取り出します。

colnames(World)
##  [1] "iso_a3"       "name"         "sovereignt"   "continent"    "area"        
##  [6] "pop_est"      "pop_est_dens" "economy"      "income_grp"   "gdp_cap_est" 
## [11] "life_exp"     "well_being"   "footprint"    "inequality"   "HPI"         
## [16] "geometry"

III.Simple maps

平均余命(life_exp)で地図を描きます。

tm_shape(World) +
  tm_polygons("life_exp")

IV.Interactive maps

はじめにモードを指定します。

次のようにエラーになりました。

上のエラーが出たは、先にコメントにあるオプションを書きます。

tmap_options(check.and.fix = TRUE)
tmap_mode("view")
## tmap mode set to interactive viewing
tm_shape(World) +
    tm_polygons("HPI")
## Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1

To be continued.