世界地図の設定

#install.packages(c("cowplot", "googleway","ggplot2", "ggrepel", "ggspatial", "libwgeom", "sf", "rnaturalearth","rnaturalearthdata"))
library("ggplot2")
theme_set(theme_bw())
library("sf")
library("rnaturalearth")
library("rnaturalearthdata")

world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
## [1] "sf"         "data.frame"
# 必要な変数に絞る
world2<-world[,c(18,45)]
ggplot(data = world) +
    geom_sf()

Data of ownership

library(readxl)
map_ownership <- read_excel("map_ownership.xlsx")

#変数名変更
map_ownership$Ratio <- map_ownership$parent1_share01
map_ownership$iso_a3 <- map_ownership$cty
map_ownership$cty<-NULL
map_ownership$parent1_share01<-NULL
map_ownership$oecd<-NULL
map_ownership$pcrdbofgdp<-NULL


library(dplyr)
world_merged <- left_join(world2, map_ownership, by = "iso_a3")

Map of ownership

title1 <- paste0("Average ownership ratio in ",length(map_ownership$Ratio), " host countries (1989-2016)")
ggplot(data = world_merged) +
    geom_sf(aes(fill = Ratio)) +
    scale_fill_viridis_c(option = "plasma", trans = "sqrt") +
  ggtitle(title1)

ggsave("figA1_map_ownership_plasma.jpg", width = 8, height = 4, dpi = "print")

別のつくり方

https://bookdown.org/mcwimberly/gdswr-book/mapping-with-ggplot2.html

出資比率

cap1 <- paste0(length(map_ownership$Ratio), " host countries (1989-2016)")
ggp1 <-ggplot(data = world_merged) +
    geom_sf(aes(fill = Ratio)) +
    scale_fill_distiller(name="Ratio", palette = "Reds", direction=1)+
  labs(title="",caption=cap1) +
  coord_sf(xlim = c(-180, 180), ylim = c(85, -55), expand = TRUE)+
   theme(axis.text = element_blank(), axis.title = element_blank())

ggp1 

ggsave("figA1_map_ownership.jpg", width = 8, height = 4, dpi = "print")
ggsave("figA1_map_ownership.eps", width = 8, height = 4, dpi = "print")

完全所有の割合

direction=1 or -1 で色の順番を変更できる。

cap1 <- paste0(length(map_ownership$wos), " host countries (1989-2016)")
ggp2 <- ggplot(data = world_merged) +
    geom_sf(aes(fill = Ratio)) +
    scale_fill_distiller(name="Whole ownership", palette = "Reds", direction=1)+
  labs(title="",caption=cap1) +
  coord_sf(xlim = c(-180, 180), ylim = c(85, -55), expand = TRUE)+
   theme(axis.text = element_blank(), axis.title = element_blank())

ggsave("figA1_map_wos.jpg", width = 8, height = 4, dpi = "print")
ggsave("figA1_map_wos.eps", width = 8, height = 4, dpi = "print")

2つの地図を合わせる

https://statisticsglobe.com/draw-multiple-ggplot-plots-side-by-side

#install.packages("gridExtra")               # Install gridExtra package
library("gridExtra")                        # Load gridExtra package
grid.arrange(ggp1, ggp2, nrow = 2)          # Apply grid.arrange function

# rgeosがCRANから削除されてしまったので、アーカイブサイトからダウンロードして、インストール。
# https://cran.r-project.org/src/contrib/Archive/rgeos/
library(rgeos) 

library(rworldmap)
library(rworldxtra)
#方法1
# get world map
wmap <- getMap(resolution="high")
# wmapをデータに変換すると重心の緯度経度ある
wmap_data <- as.data.frame(wmap)

library(dplyr)
world_merged$ISO3<-world_merged$iso_a3
world_merged2 <- left_join(world_merged,wmap_data,by="ISO3")

world_merged2$n_aff2<- (world_merged2$n_aff)/500

ggplot() +
  geom_sf(data = world_merged2,aes(fill = Ratio)) +
    scale_fill_distiller(name="Ratio", palette = "Blues")+
  geom_point(data = world_merged2, aes(x = LON, y = LAT), size = world_merged2$n_aff2, 
        shape = 23, fill = "darkred") 

References