1. ๊ธ€๋กœ๋ฒŒ ์ž๋™์ฐจ ๋ถ€ํ’ˆ ๊ณต๊ธ‰์‚ฌ

Automotive News์‚ฌ์—์„œ ๋งค๋…„ ์ž๋™์ฐจ ๊ณต๊ธ‰์‚ฌ 100๊ฐœ๋ฅผ ๋ฝ‘์•„์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์žˆ๋‹ค. Automotive News ์„ ์ • Top Supplier Rankings์— ๋ฐ์ดํ„ฐ๊ฐ€ 2005๋…„๋ถ€ํ„ฐ ์ตœ๊ทผ๊นŒ์ง€ ๋ฐ์ดํ„ฐ๊ฐ€ ์ž˜ ์ •๋ฆฌ๋˜์–ด ์žˆ๋‹ค.

2. ๊ธ€๋กœ๋ฒŒ ์ž๋™์ฐจ ๋ถ€ํ’ˆ ๊ณต๊ธ‰์‚ฌ ๋ฐ์ดํ„ฐ

2.1. ํ™˜๊ฒฝ์„ค์ •๊ณผ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

์˜คํ† ๋‰ด์Šค ์›น์‚ฌ์ดํŠธ์—์„œ ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๊ณ  ๋ฐ์ดํ„ฐ๋ถ„์„์— ํ•„์š”ํ•œ ํŒฉํ‚ค์ง€๋ฅผ ์‚ฌ์ „ ์ค€๋น„ํ•œ๋‹ค.

# 0. ํ™˜๊ฒฝ์„ค์ • ----------------
# library(readxl)
# library(tidyverse)
# library(stringr)
# library(forcats)
# library(ggpubr)
# library(extrafont)
# loadfonts()
# library(xts)
# library(ggmap)
# library(leaflet)

# 1. ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ ---------------
autonews_dat <- read_excel("data/CA105777620.XLS", sheet="Top 100 Global Suppliers (2016)", skip=1)

2.2. ๋ฐ์ดํ„ฐ ์ •์ œ

์—‘์…€๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ์ž˜ ์ •๋ฆฌ๋˜์–ด ์žˆ์ง€๋งŒ ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ ํ˜•ํƒœ๋กœ ๋ฐ์ดํ„ฐ ๋ถ„์„ํ•˜๊ธฐ ์ ์ ˆํ•œ ํ˜•ํƒœ๋กœ ๊ฐ€๊ณตํ•œ๋‹ค. ํŠนํžˆ, ๊ฐ ๋ถ€ํ’ˆ๊ณต์‚ฌ๋งˆ๋‹ค ๊ณต๊ธ‰ํ•˜๋Š” ์ œํ’ˆ๊ณผ ์ฃผ์†Œ๋ฅผ ์ ์ ˆํ•œ ์ •์ œ๊ณผ์ •์„ ๊ฑฐ์ณ ๊น”๋”ํ•˜๊ฒŒ ์ •๋ฆฌํ•œ๋‹ค.

# 2. ๋ฐ์ดํ„ฐ ์ •์ œ ---------------
## 2.1. ์ž๋™์ฐจ ๊ณต๊ธ‰์‚ฌ ๋ชฉ๋ก -----
autonews_df <- autonews_dat %>% 
  filter(!is.na(`2015\nrank`)) %>% 
  filter(row_number() <= 247)

## 2.2. ์ž๋™์ฐจ ์ œ์กฐํ’ˆ๋ชฉ -----
autonews_product_df <- autonews_dat %>% select(`2015\nrank`, Products) %>% 
  filter(row_number() <= 247) %>% 
  mutate(`2015\nrank` = na.locf(`2015\nrank`)) %>%  group_by(`2015\nrank`) %>% 
  summarise(items = paste0(Products, collapse = ",")) %>% 
  mutate(items = str_replace(items, ",NA$", ""))

## 2.2. ์ž๋™์ฐจ ์ œ์กฐํ’ˆ๋ชฉ -----
autonews_address_df <- autonews_dat %>% select(`2015\nrank`, Address) %>% 
  filter(row_number() <= 247) %>% 
  mutate(`2015\nrank` = na.locf(`2015\nrank`)) %>%  group_by(`2015\nrank`) %>% 
  summarise(address = paste0(Address, collapse = ","))  %>% 
  mutate(address = str_replace(address, ",NA", ""))

## 2.3. ์ž๋™์ฐจ ๋ถ€ํ’ˆ์‚ฌ์™€ ์ œ์กฐํ’ˆ๋ชฉ ๋ณ‘ํ•ฉ -----

autonews_df <- left_join(autonews_df, autonews_product_df, "2015\nrank") %>% 
  select(-X__1, -X__2, -X__3, -Products) 

autonews_df <- left_join(autonews_df, autonews_address_df, "2015\nrank") %>% 
  select(-Address) 

colnames(autonews_df) <- c(c("rank_2015", "company", "top_executive", "sales_2015", 
                             "sales_2014", "NA_percent", "EU_percent", "AS_percent", 
                             "ETC_percent", "rank_2014", "items", "address"))

autonews_df <- autonews_df %>% 
  mutate(NA_percent = ifelse(is.na(NA_percent), 0, NA_percent),
         EU_percent = ifelse(is.na(EU_percent), 0, EU_percent),
         AS_percent = ifelse(is.na(AS_percent), 0, AS_percent),
         ETC_percent = ifelse(is.na(ETC_percent), 0, ETC_percent))

DT::datatable(autonews_df)  

3. ๋ถ€ํ’ˆ๊ณต๊ธ‰์‚ฌ ๋ณธ์‚ฌ ์ฃผ์†Œ

๋ณธ๊ฒฉ์ ์ธ ๋ฐ์ดํ„ฐ ๋ถ„์„์— ์•ž์„œ ๋ถ€ํ’ˆ๊ณต๊ธ‰์‚ฌ๊ฐ€ ์œ„์น˜ํ•œ ์ฃผ์†Œ ์ •๋ณด๋ฅผ ์ด์šฉํ•˜์—ฌ ์ „์„ธ๊ณ„ ์ง€๋„์œ„์— ํ‘œ๊ธฐํ•œ๋‹ค. ์•ž์„œ ggmap ํŒฉํ‚ค์ง€ geocode() ํ•จ์ˆ˜๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์œ„๊ฒฝ๋„ ์ •๋ณด๋ฅผ ๋ฐ›์•„ ๋†“๊ณ  ์ด๋ฅผ ์กฐ์ธํ•˜์—ฌ ์ง€๋„์œ„์— ํ‘œ๊ธฐํ•œ๋‹ค.

# 1. ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ ---------------
supplier_df <- readRDS("data_processed/autonews_df.rds") %>% 
  mutate(address = str_replace(address, ",NA", ""))

supplier_lonlat <- readRDS("data_processed/supplier_lonlat.rds")

# 2. ์ง€๋ฆฌ์ •๋ณด ---------------
## 2.1. ์ง€๋ฆฌ์ •๋ณด ๋ฐ์ดํ„ฐ: ์œ„๋„ ๊ฒฝ๋„ ---

# supplier_lonlat <- geocode(supplier_df$address, source="google")
# saveRDS(supplier_lonlat, "data_processed/supplier_lonlat.rds")

supplier_lonlat_df <- bind_cols(supplier_df, supplier_lonlat)

# saveRDS(supplier_lonlat_df, "data_processed/supplier_lonlat_df.rds")

supplier_geo_df <- read_excel("data/supplier_address_csv.xlsx")

leaflet(data = supplier_geo_df) %>% 
  addProviderTiles(providers$OpenStreetMap) %>% 
  addMarkers(lng=~Longitude, lat=~Latitude, 
             popup = ~ as.character(paste0("<strong> ๊ธ€๋กœ๋ฒŒ ์ž๋™์ฐจ ๋ถ€ํ’ˆ๊ณต๊ธ‰์‚ฌ </strong><br><br>", 
                                           "&middot; ์ˆœ์œ„(2015): ", rank_2015, "<br>",
                                           "&middot; ํšŒ์‚ฌ๋ช…: ", company, "<br>",
                                           "&middot; ์ฃผ์†Œ: ", address, "<br>",
                                           "&middot; ๋Œ€ํ‘œ: ", top_executive, "<br>",
                                           "&middot; ๋งค์ถœ(๋ฐฑ๋งŒ$): ", scales::comma(sales_2015), "<br>",
                                           "&nbsp&nbsp&nbsp &middot; ๋ถ๋ฏธ: ", NA_percent, " %<br>",
                                           "&nbsp&nbsp&nbsp &middot; ์œ ๋Ÿฝ: ", EU_percent, " %<br>",
                                           "&nbsp&nbsp&nbsp &middot; ์•„์‹œ์•„: ", AS_percent, " %<br>",
                                           "&nbsp&nbsp&nbsp &middot; ๊ธฐํƒ€: ", ETC_percent, " %<br>",
                                           "&middot; ๊ณต๊ธ‰๋ถ€ํ’ˆ: ", items, "<br>")), clusterOptions = markerClusterOptions())