1 Load the package

library(ggplot2)
library(tidyverse)
library(rio)

2 Load the data

# Load the GBR data
library(rio)
SHJP_JP_FA_GBR <- rio::import("../Data_output/SHJP_JP_FA_GBR.rds")

# Select necessary columns
SHJP_JP_FA_GBR <- SHJP_JP_FA_GBR %>% 
  select(AffiliateCode, year, AffiliateNameAlph, JPCode, Parent_NameAlphabet, 
         county, city, lat, lon, AddressAlph, countryname,
         PayrollNumber, StartDate, FA_Sector, FA_SectorName)


# Create lmean 
PayrollNumber_mean <- mean(SHJP_JP_FA_GBR$PayrollNumber, na.rm = TRUE)
SHJP_JP_FA_GBR$l <- ifelse(is.na(SHJP_JP_FA_GBR$PayrollNumber), PayrollNumber_mean, SHJP_JP_FA_GBR$PayrollNumber)

3 Desribe the location of Japanese affiliate

# Barplot of number of affiliate by county in 1990
SHJP_JP_FA_GBR %>%
  filter(year == 1990) %>%
  group_by(county) %>%
  summarise(N = n()) %>%
  # keep the top county
  top_n(30, N) %>%
  ggplot(aes(x = county, y = N)) +
  geom_bar(stat = "identity") +
  labs(title = "Number of Japanese affiliate in the UK",
       x = "county",
       y = "Number of affiliate") +
  theme_minimal() +
  # make the graph horizontal
  coord_flip()

4 Map the Japanese affiliate with leaflet in 2014

# subset the data, 2014
SHJP_JP_FA_GBR2014 <- subset(SHJP_JP_FA_GBR, year == 2014)
# subset the data, 2020
SHJP_JP_FA_GBR2020 <- subset(SHJP_JP_FA_GBR, year == 2020)

# 2014
library(leaflet)
leaflet(data = SHJP_JP_FA_GBR2014) %>% addTiles() %>% 
  addCircleMarkers(lng = ~lon, lat = ~lat, radius = ~l/1000, 
                   color = "blue", popup = ~AffiliateNameAlph,
                   ) 

5 Map the Japanese affiliate with leaflet in 2020

# 2020
leaflet(data = SHJP_JP_FA_GBR2020) %>% addTiles() %>% 
  addCircleMarkers(lng = ~lon, lat = ~lat, radius = ~l/10000, 
                   color = "blue", popup = ~AffiliateNameAlph)

6 Map the Japanese affiliate with leaflet: 2014

library(leaflet)
leaflet(data = SHJP_JP_FA_GBR2014) %>% addTiles() %>% 
  addMarkers(lng = ~lon, lat = ~lat, 
             popup = ~as.character(AffiliateNameAlph), 
             label = ~as.character(Parent_NameAlphabet),
             clusterOptions = TRUE)

7 Map the Japanese affiliate with leaflet: 2020

library(leaflet)
leaflet(data = SHJP_JP_FA_GBR2020) %>% addTiles() %>% 
  addMarkers(lng = ~lon, lat = ~lat, 
             popup = ~as.character(AffiliateNameAlph), 
             label = ~as.character(Parent_NameAlphabet),
             clusterOptions = TRUE)

8 Load the map of rnaturalearth

  • ne_countries() function is used to load the map of the UK.
  • The map is plotted with ggplot2.
library(rnaturalearth)
library(rnaturalearthdata)
#library(rnaturalearthhires)

# load the map of the UK
ukmap <- ne_countries(country = "United Kingdom", 
                      returnclass = "sf", scale = "medium")

# Plot the map
ggplot(ukmap) + geom_sf(alpha = 0.4) 

plot(ukmap)

9 Drop Jersey

# Drop Jersey
SHJP_JP_FA_GBR2020 <- SHJP_JP_FA_GBR2020 %>%
  filter(county != "Jersey")


# Keep the observation with lat >=48 & lat <= 60
SHJP_JP_FA_GBR2020 <- SHJP_JP_FA_GBR2020 %>%
  filter(lat >= 48 & lat <= 60)

10 Plot the location of Japanese affiliate in the UK map in 2020

library(ggplot2)
library(ggthemes)
library(ggrepel)

# Plot the location of Japanese affiliate in the UK map
ggplot() +
  geom_sf(data = ukmap) +
  geom_point(data = SHJP_JP_FA_GBR2020, aes(x = lon, y = lat), 
             size = 2, alpha = 0.3, color = "blue") +
  theme_map() +
  # limit the y-axis
  coord_sf(xlim = c(-10, 2), ylim = c(48, 60)) +
  theme(legend.position = "bottom")