필요한 패키지 로드

library(dplyr)
library(ggplot2)
library(readxl)
library(gridExtra)
library(knitr)
library(kableExtra)
library(magrittr)
library(rnaturalearth)
library(sf)



여행지를 선정하는 첫번째 기준 - 위험도


asia_risk <- read_excel("C:/Users/kimminjun/Downloads/아시아 지역 위험도.xlsx")
world <- ne_countries(scale = "medium", returnclass = "sf")
asia <- world[world$continent == "Asia", ] # 아시아 지도 불러오기

colnames(asia_risk)[which(names(asia_risk) == "나라")] <- "name"
colnames(asia_risk)[which(names(asia_risk) == "위험도")] <- "Risk_Level"
asia_with_risk <- merge(asia, asia_risk, by = "name", all.x = TRUE)
risk_levels <- c("Low Risk", "Moderate Risk", "Elevated Risk", "High Risk")
risk_colors <- c("#2ca25f", "#fee08b","#fdae61", "#d73027")

ggplot() + geom_sf(data = asia_with_risk, aes(fill = factor(Risk_Level, levels = risk_levels)), color = "white", alpha = 0.7) +
  scale_fill_manual(values = c("Low Risk" = "#2ca25f", "Moderate Risk" = "#fee08b", "Elevated Risk" = "#fdae61", "High Risk" = "#d73027"),
                    na.value = "gray") + theme_minimal() + guides(fill = guide_legend(title = "Risk Level", reverse = TRUE)) # 지도 그리기


<도쿄, 삿포로, 오사카, 후쿠오카, 홍콩, 다낭>



여행지를 선정하는 두번째 기준 - 기온


tokyo_weather <- data.frame(Country = rep("도쿄", 2), Month = c("1월", "2월"), Min_Temperature= c(2.5, 2.9), Max_Temperature = c(9.9, 10.4)) # 도쿄 날씨 데이터
sapporo_weather <- data.frame(Country = rep("삿포로", 2),Month = c("1월", "2월"), Min_Temperature = c(-7.0, -6.6), Max_Temperature = c(-0.6, 0.1)) # 삿포로 날씨 데이터
osaka_weather <- data.frame(Country = rep("오사카", 2), Month = c("1월", "2월"), Min_Temperature = c(2.8, 2.9), Max_Temperature = c(9.5, 10.2)) # 오사카 날씨 데이터
fukuoka_weather <- data.frame(Country = rep("후쿠오카", 2), Month = c("1월", "2월"), Min_Temperature = c(3.5, 4.1), Max_Temperature = c(9.9, 11.1)) # 후쿠오카 날씨 데이터
hongkong_weather <- data.frame(Country = rep("홍콩", 2), Month = c("1월", "2월"), Min_Temperature = c(14.6, 15.3), Max_Temperature = c(18.7, 19.4)) # 홍콩 날씨 데이터
danang_weather <- data.frame(Country = rep("다낭", 2), Month = c("1월", "2월"), Min_Temperature = c(19.7, 20.4), Max_Temperature = c(25.2, 26.3)) # 다낭 날씨 데이터
kotakinabalu_weather <- data.frame(Country = rep("코타키나발루", 2), Month = c("1월", "2월"), Min_Temperature = c(22.9, 23.0), Max_Temperature = c(30.4, 30.7)) # 코타키나발루 날씨 데이터
weather_data <- rbind(tokyo_weather, sapporo_weather, osaka_weather, fukuoka_weather, hongkong_weather,danang_weather, kotakinabalu_weather)
weather_data <- weather_data %>% mutate(Month = as.numeric(gsub("월", "", Month)))

plot_january_min <- ggplot(subset(weather_data, Month == 1), aes(x = Country, fill = Country)) +
  geom_bar(aes(y = Min_Temperature), stat = "identity", position = "dodge", width = 0.35) +
  labs(title = "1월 나라별 최저기온", x = "도시", y = "기온(°C)", fill = "도시") +
  scale_fill_manual(values = c("도쿄" = "#FFB6C1", "삿포로" = "#ADD8E6", "오사카" = "#98FB98", "후쿠오카" = "#FFA500", "홍콩" = "#D8BFD8", "다낭" = "#D2B48C", "코타키나발루" = "#FF69B4")) + theme_minimal() + theme(axis.text.x = element_text(angle = 45, hjust = 1))

plot_january_max <- ggplot(subset(weather_data, Month == 1), aes(x = Country, fill = Country)) +
  geom_bar(aes(y = Max_Temperature), stat = "identity", position = "dodge", width = 0.35) +
  labs(title = "1월 나라별 최고기온", x = "도시", y = "기온(°C)", fill = "도시") +
  scale_fill_manual(values = c("도쿄" = "#FFB6C1", "삿포로" = "#ADD8E6", "오사카" = "#98FB98", "후쿠오카" = "#FFA500", "홍콩" = "#D8BFD8", "다낭" = "#D2B48C", "코타키나발루" = "#FF69B4")) + theme_minimal() + theme(axis.text.x = element_text(angle = 45, hjust = 1)) # 1월 그래프

plot_february_min <- ggplot(subset(weather_data, Month == 2), aes(x = Country, fill = Country)) +
  geom_bar(aes(y = Min_Temperature), stat = "identity", position = "dodge", width = 0.35) +
  labs(title = "2월 나라별 최저기온", x = "도시", y = "기온(°C)", fill = "도시") +
  scale_fill_manual(values = c("도쿄" = "#FFB6C1", "삿포로" = "#ADD8E6", "오사카" = "#98FB98", "후쿠오카" = "#FFA500", "홍콩" = "#D8BFD8", "다낭" = "#D2B48C", "코타키나발루" = "#FF69B4")) +
  theme_minimal() + theme(axis.text.x = element_text(angle = 45, hjust = 1))

plot_february_max <- ggplot(subset(weather_data, Month == 2), aes(x = Country, fill = Country)) +
  geom_bar(aes(y = Max_Temperature), stat = "identity", position = "dodge", width = 0.35) +
  labs(title = "2월 나라별 최고기온", x = "도시", y = "기온(°C)", fill = "도시") +
  scale_fill_manual(values = c("도쿄" = "#FFB6C1", "삿포로" = "#ADD8E6", "오사카" = "#98FB98", "후쿠오카" = "#FFA500", "홍콩" = "#D8BFD8", "다낭" = "#D2B48C", "코타키나발루" = "#FF69B4")) + theme_minimal() + theme(axis.text.x = element_text(angle = 45, hjust = 1)) # 2월 그래프

grid.arrange(plot_january_min, plot_january_max,plot_february_min, plot_february_max, ncol = 2)




filtered_weather_data <- weather_data %>% group_by(Country) %>% filter(all(Max_Temperature <= 20) & all(Min_Temperature >= 0)) # 필터링
summarized_data <- filtered_weather_data %>% group_by(Country) %>% summarize(Month = paste(unique(Month), collapse = ","))
kable(summarized_data)
Country Month
도쿄 1,2
오사카 1,2
홍콩 1,2
후쿠오카 1,2




여행지를 선정하는 세번째 기준 - 가격


incheon_tokyo_price <- read_excel("C:/Users/kimminjun/Downloads/인천-도쿄.xlsx")
incheon_osaka_price <- read_excel("C:/Users/kimminjun/Downloads/인천-오사카.xlsx")
incheon_fujuoka_price <- read_excel("C:/Users/kimminjun/Downloads/인천-후쿠오카.xlsx")
incheon_hongkong_price <- read_excel("C:/Users/kimminjun/Downloads/인천-홍콩.xlsx") # 데이터 불러오기

incheon_fujuoka_price$날짜 <- as.Date(incheon_fujuoka_price$날짜, format = "incheon_fujuoka_price")
plot_fujuoka<-ggplot(incheon_fujuoka_price, aes(x = 날짜, y = 가격)) + geom_line(aes(group = 1), color = "skyblue", size = 2) +
  labs(title = "인천-후쿠오카 항공권 가격", x = NULL, y = "가격") + theme_minimal() + theme(axis.text.x = element_blank(), axis.ticks.x = element_blank())

incheon_hongkong_price$날짜 <- as.Date(incheon_hongkong_price$날짜, format = "incheon_hongkong_price")
plot_hongkong<-ggplot(incheon_hongkong_price, aes(x = 날짜, y = 가격)) + geom_line(aes(group = 1), color = "skyblue", size = 2) + 
  labs(title = "인천-홍콩 항공권 가격", x = NULL, y = "가격") + theme_minimal() + theme(axis.text.x = element_blank(), axis.ticks.x = element_blank())

incheon_osaka_price$날짜 <- as.Date(incheon_osaka_price$날짜, format = "incheon_osaka_price")
plot_osaka<-ggplot(incheon_osaka_price, aes(x = 날짜, y = 가격)) + geom_line(aes(group = 1), color = "skyblue", size = 2) +
  labs(title = "인천-오사카 항공권 가격", x = NULL, y = "가격") + theme_minimal() + theme(axis.text.x = element_blank(), axis.ticks.x = element_blank())

incheon_tokyo_price$날짜 <- as.Date(incheon_tokyo_price$날짜, format = "incheon_tokyo_price")
plot_tokyo<-ggplot(incheon_tokyo_price, aes(x = 날짜, y = 가격)) + geom_line(aes(group = 1), color = "skyblue", size = 2) +
  labs(title = "인천-도쿄 항공권 가격", x = NULL, y = "가격") + theme_minimal() + theme(axis.text.x = element_blank(), axis.ticks.x = element_blank()) 

grid.arrange(plot_fujuoka, plot_hongkong, plot_osaka, plot_tokyo, ncol = 2) # 그래프 그리기




첫번째 인천-후쿠오카 항공권은 2개가 조회됨

incheon_fujuoka_price_1 <- incheon_fujuoka_price %>% mutate(가격 = gsub("[^0-9]", "", 가격))
incheon_fujuoka_price_1 <- incheon_fujuoka_price_1 %>% filter(as.numeric(가격) <= 280000) # 가격이 280000을 초과하는 행 제거
print(incheon_fujuoka_price_1)
## # A tibble: 2 × 2
##   날짜       가격  
##   <date>     <chr> 
## 1 2024-01-01 258400
## 2 2024-02-06 278400

두번째 인천-홍콩 항공권은 5개가 조회됨

incheon_hongkong_price_1 <- incheon_hongkong_price %>% mutate(가격 = gsub("[^0-9]", "", 가격))
incheon_hongkong_price_1 <- incheon_hongkong_price_1 %>% filter(as.numeric(가격) <= 280000) # 가격이 280000을 초과하는 행 제거
print(incheon_hongkong_price_1)
## # A tibble: 5 × 2
##   날짜       가격  
##   <date>     <chr> 
## 1 2024-01-16 273600
## 2 2024-01-27 273100
## 3 2024-02-25 277100
## 4 2024-02-27 277100
## 5 2024-02-28 277100

세번째 인천-오사카 항공권은 0개가 조회됨

incheon_osaka_price_1 <- incheon_osaka_price %>% mutate(가격 = gsub("[^0-9]", "", 가격))
incheon_osaka_price_1 <- incheon_osaka_price_1 %>% filter(as.numeric(가격) <= 280000) # 가격이 280000을 초과하는 행 제거
print(incheon_osaka_price_1)
## # A tibble: 0 × 2
## # ℹ 2 variables: 날짜 <date>, 가격 <chr>

네번째 인천-도쿄 항공권은 0개가 조회됨

incheon_tokyo_price_1 <- incheon_tokyo_price %>% mutate(가격 = gsub("[^0-9]", "", 가격))
incheon_tokyo_price_1 <- incheon_tokyo_price_1 %>% filter(as.numeric(가격) <= 280000) # 가격이 280000을 초과하는 행 제거
print(incheon_tokyo_price_1)
## # A tibble: 0 × 2
## # ℹ 2 variables: 날짜 <date>, 가격 <chr>



결과



best <- data.frame(
  Country = c("후쿠오카", "후쿠오카", "홍콩", "홍콩", "홍콩", "홍콩", "홍콩"),
  Date = c("2024-01-01", "2024-02-06", "2024-01-16", "2024-01-27", "2024-02-25", "2024-02-27", "2024-02-28"),
  Price = c(258400, 278400, 273600, 273100, 277100, 277100, 277100)) #데이터 프레임 만들기
table <- kable(best, format = "html", caption = "") %>% kable_styling(full_width = F) %>%
  row_spec(0, bold = TRUE) %>% row_spec(1:nrow(best), background = "white")
table
Country Date Price
후쿠오카 2024-01-01 258400
후쿠오카 2024-02-06 278400
홍콩 2024-01-16 273600
홍콩 2024-01-27 273100
홍콩 2024-02-25 277100
홍콩 2024-02-27 277100
홍콩 2024-02-28 277100

Date는 3일 왕복 기준 출발날이며 Price는 왕복 항공료를 의미함

choice <- data.frame(
  Country = c("후쿠오카", "홍콩","홍콩"),
  Date = c("2024-02-06", "2024-01-16","2024-01-27"),
  Price = c(258400, 273600,273100)) #데이터 프레임 만들기
table <- kable(choice, format = "html", caption = "") %>% kable_styling(full_width = F) %>%
  row_spec(0, bold = TRUE) %>% row_spec(1:nrow(choice), background = "white")
table
Country Date Price
후쿠오카 2024-02-06 258400
홍콩 2024-01-16 273600
홍콩 2024-01-27 273100

Date는 3일 왕복 기준 출발날이며 Price는 왕복 항공료를 의미함


이번 겨울 최적의 여행지로 <2024-02-06 후쿠오카>, <2024-01-16 홍콩>, <2024-01-27 홍콩>을 기준에 따라 선정함