INTRODUCTION

    Dataset perjalanan memberikan informasi rinci tentang berbagai perjalanan yang dilakukan oleh wisatawan. Kumpulan data ini dapat digunakan untuk mendapatkan wawasan tentang pola perjalanan, preferensi, dan perilaku berbagai jenis wisatawan. Hal ini juga dapat bermanfaat bagi bisnis yang berhubungan dengan perjalanan, seperti agen perjalanan, untuk menciptakan strategi pemasaran dan paket perjalanan yang disesuaikan dengan kebutuhan dan preferensi wisatawan yang berbeda. Dari data ini kita akan menggunakan beberapa fungsi yang ada dalam pemrograman yang ada di R. Hingga hasil akhirnya kita bisa jadikan bentuk visualisasi.

link : https://www.kaggle.com/datasets/rkiattisak/traveler-trip-data

IMPORT LIBRARY

# import Libary
library(ggplot2)
library(ggpubr)
library(scales)
library(glue)
library(plotly)
library(lubridate)
library(dplyr)

READ DATA

Hal pertama yang harus kita lakukan yaitu import data kita terlebih dahulu read.csv.

# Please type your code here
world_travel <- read.csv("travel_details_dataset2023AA.csv")

DATA INSPECTIONS

Kita gunakan head() untuk melihat urutan data teratas dan gunakan tail() untuk melihat urutan data paling bawah.

head(world_travel)
tail(world_travel)

Melihat struktur data yang dimiliki dapat menggunakan fungsi glimpse().

glimpse(world_travel)
#> Rows: 137
#> Columns: 15
#> $ Trip.ID              <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15…
#> $ Destination          <chr> "London, UK", "Phuket, Thailand", "Bali, Indonesi…
#> $ City                 <chr> "London", "Phuket", "Bali", "New York City", "Tok…
#> $ Country              <chr> "UK", "Thailand", "Indonesia", "USA", "Japan", "F…
#> $ Start.Date           <chr> "1/5/2023", "06/15/2023", "1/7/2023", "08/15/2023…
#> $ End.Date             <chr> "8/5/2023", "06/20/2023", "8/7/2023", "08/29/2023…
#> $ Duration_days        <int> 7, 5, 7, 14, 7, 5, 10, 7, 7, 7, 7, 7, 8, 9, 7, 7,…
#> $ Traveler.Name        <chr> "John Smith", "Jane Doe", "David Lee", "Sarah Joh…
#> $ Traveler.Age         <int> 35, 28, 45, 29, 26, 42, 33, 25, 31, 39, 27, 36, 2…
#> $ Traveler.Gender      <chr> "Male", "Female", "Male", "Female", "Female", "Ma…
#> $ Traveler.Nationality <chr> "American", "Canadian", "Korean", "British", "Vie…
#> $ Accom.Type           <chr> "Hotel", "Resort", "Villa", "Hotel", "Airbnb", "H…
#> $ Accom.Cost           <int> 1200, 800, 1000, 2000, 700, 1500, 500, 900, 1200,…
#> $ Trans.Type           <chr> "Flight", "Flight", "Flight", "Flight", "Train", …
#> $ Trans.Cost           <int> 600, 500, 700, 1000, 200, 800, 1200, 600, 200, 80…

Dengan menggunakan fungsi glimpse() kita mendapatkan informasi bahwa data kita terdapat 137 baris dan 15 columns. Memuat informasi columns sebagai berikut :

`Trip.ID `                : Pengidentifikasi no unik untuk setiap perjalanan yang dilakukan oleh wisatawan.
`Destination`             : Nama kota dan negara yang dikunjungi traveler.
`City`                    : Nama kota yang dikunjungi traveler.
`Country`                 : Nama negara yang dikunjungi traveler.
`Start.Date`              : Tanggal wisatawan memulai perjalanan.
`End.Date`                : Tanggal wisatawan mengakhiri perjalanan.
`Duration_days`           : Jumlah hari yang dihabiskan wisatawan dalam perjalanan.
`Traveler.Name`           : Nama wisatawan/pelancong.
`Traveler.Age`            : Usia pelancong pada saat perjalanan.
`Traveler.Gender`         : Jenis kelamin pelancong.
`Traveler.Nationality`    : Kebangsaan pelancong.
`Accom.Type`              : Jenis akomodasi tempat wisatawan menginap.
`Accom.Cost`              : Biaya akomodasi untuk seluruh perjalanan.
`Trans.Type`              : Moda transportasi yang digunakan pelancong.
`Trans.Cost`              : Biaya transportasi untuk seluruh perjalanan.

CLEANSING DATA & PRE-PROCESSING

Kita check apakah terdapat missing value atau tidak pada data yang kita miliki menggunakan fungsi colsums(is.na()).

mengecek col NA

colSums(is.na(world_travel))
#>              Trip.ID          Destination                 City 
#>                    0                    0                    0 
#>              Country           Start.Date             End.Date 
#>                    0                    0                    0 
#>        Duration_days        Traveler.Name         Traveler.Age 
#>                    0                    0                    0 
#>      Traveler.Gender Traveler.Nationality           Accom.Type 
#>                    0                    0                    0 
#>           Accom.Cost           Trans.Type           Trans.Cost 
#>                    0                    0                    0

Setelah kita melakukan pengecekan missing value menggunakan fungsi anyNA() tidak terdapat missing value di tandai dengan munculnya FALSE pada output

Kita buang columns yang tidak kita butuhkan dengan menggunakan fungsi select(), lalu yang terakhir ubah tipe data yang kita miliki dengan tipe data yang sesuai menggunakan fungsi mmutate().

# data cleansing
city_country <- world_travel %>% 
  select(-c(City, Country)) %>% 
  mutate(
    Start.Date = mdy(Start.Date),
    End.Date = mdy(End.Date),
    Accom.Cost = as.numeric(Accom.Cost),
    Accom.Type = as.factor(Accom.Type)
  )
city_country

INTERACTIVE PLOTTING

Chart A

country_travel <- city_country %>% 
  group_by(Destination) %>% 
  summarise (freq = n()) %>% 
  arrange(-freq) %>% 
  head(10)

country_travel <- country_travel %>% 
  mutate(label = glue("Category: {Destination}
                      Frequency: {freq}"))

plot_hits <- ggplot(data = country_travel, aes(x = freq,
                                       y = reorder(Destination, freq),
                                       text = label)) +
  geom_col(aes(fill = freq)) +
  scale_fill_gradient(low = "orange", high = "red") +
  labs(title = "Destination Trip",
       x = "Frequency",
       y = NULL) +
  theme_minimal() +
  theme(legend.position = "none")

ggplotly(plot_hits, tooltip = "text")

Chart B

travel_top <- city_country %>% 
  filter(Destination %in% "Paris, France") %>% 
  group_by(Traveler.Nationality) %>% 
  summarise(Accom.Cost = mean(Accom.Cost)) %>% 
  arrange(-Accom.Cost)

travel_top <-  travel_top %>% 
   mutate(label = glue("Accom: {Traveler.Nationality}
                        Mean: {Accom.Cost}"))

plot_accom <- ggplot(data = travel_top, 
                aes(x = reorder(Traveler.Nationality, Accom.Cost),
                    y = Accom.Cost,
                    text = label,
                    color = Accom.Cost)) +
  geom_point(size = 2) +
  geom_segment(aes(x = reorder(Traveler.Nationality, Accom.Cost),
                   xend = reorder(Traveler.Nationality, Accom.Cost),
                   y = 0,
                   yend = Accom.Cost), linewidth = 1.5) +
  scale_color_gradient(low = "green",
                       high = "navy") +
  coord_flip() +
  scale_y_continuous(labels = comma) +
  labs(title = "Top Traveler Nationality",
       x = NULL,
       y = "Average Accom.Cost") +
  theme_minimal() +
  theme(legend.position = "none")

ggplotly(plot_accom, tooltip = "text")

Chart C

accom_trav <- city_country %>% 
  filter(Destination %in% "Paris, France") %>% 
  group_by(Traveler.Age) %>% 
  summarise(Accom.Cost = mean(Accom.Cost)) %>%  
  mutate(label = glue("Traveler.Age: {Traveler.Age}
                      Average Accom.Cost: {comma(round(Accom.Cost))}"))

plot_line <- ggplot(data = accom_trav,
                    aes(x = Traveler.Age,
                        y = Accom.Cost)) +
   geom_line(col = "navy") +
  geom_point(aes(text = label)) +
  scale_y_continuous(labels = comma) +
  labs(title = "Transportation Costs For The Age of The User",
       x = "Traveler Age",
       y = "Accomodation Cost") +
  theme_minimal() +
  theme(plot.title = element_text(hjust=0.5))

ggplotly(plot_line, tooltip = "text")

Chart D

country_travel <- city_country %>% 
  group_by(Accom.Type) %>% 
  summarise (freq = n()) %>% 
  mutate(label = glue("Accom.Type: {Accom.Type}
                      Average freq: {comma(round(freq))}")) %>% 
  arrange(-freq) %>% 
  head(10)

plot_line1 <- world_travel %>% 
  group_by(Accom.Type, Traveler.Gender) %>% 
  summarize(n = n(),
            mean = mean(Trans.Cost),
            sd = sd(Trans.Cost),
            se = sd/sqrt(n),
            ci = qt(0.975, df = n-1) * sd / sqrt(n))

pd <- position_dodge(0.2)

ggplot(plot_line1,
       aes(x = factor(Accom.Type),
           y = mean,
           group = Traveler.Gender,
           color = Traveler.Gender)) +
  geom_point(position = pd,
             size = 2.5) +
  geom_line(position = pd,
            size = 0.5) +
  scale_y_continuous(labels = scales::dollar) +
  scale_color_brewer(palette = "Set1") +
  theme_minimal() +
  labs(title = "Mean Transportation Cost by Accomodation Type & Traveler Gender",
       subtitle = "(mean +/- standard error)",
       x = NULL,
       y = NULL,
       color = "Gender")