knitr::opts_chunk$set(echo = TRUE, fig.width=5, fig.height=4, fig.align ="center", out.width = "50%" ) # global options library(ggplot2) library(foreach) library(doParallel) library(data.table) library(tidyverse) library(rmarkdown) library(tinytex) library(dplyr);library(reshape2); library(lubridate);library(stringr);library(forecast); library(pander) library(ggmap) setwd("C:/Users/JJS/Desktop/TheLorry Project-20180902T065620Z-001/TheLorry Project/data") location <- fread('location.csv', header = T) location$lat <- as.numeric(location$lat) location$lng <- as.numeric(location$lng) location_1 <- location %>% dplyr::filter(lat > 0 & lng > 0) booking <- fread('booking.csv', header = T) str(booking) # 변수 속성 변경 booking$booking_datetime <- ymd_hms(booking$booking_datetime) booking$pickup_datetime <- ymd_hms(booking$pickup_datetime) booking$distance_km <- as.numeric(booking$distance_km) booking$total_price_with_gst <- as.numeric(booking$total_price_with_gst) booking$id <- as.character(booking$id)
pickup_location <- location_1 %>% dplyr::filter(type == "pickup") map <- get_map(location = 'Malaysia', zoom = 7) pickup_map <- ggmap(map) + geom_point(aes(x = lng, y = lat), data = pickup_location, size = 0.5, col = "red") pickup_map
example_id <- location_1 %>% dplyr::filter(booking_id == 11935) map_1 <- get_map(location = c(lon = 100, lat = 3), zoom = 7, maptype = "roadmap") direction_example <- ggmap(map_1) + geom_point(aes(x = lng, y = lat, col = type), data = example_id, size = 5) direction_example
#City ## 456개 도시에서 사용 city <- location_1 %>% dplyr::count(city) %>% dplyr::arrange(desc(n)) %>% dplyr::mutate( city_1 = fct_reorder(city, n, "mean") ) ## 사용량 Top 15 city ggplot(city[1:15,], aes(x = city_1, y = n)) + geom_col() + coord_flip()
building <- location_1 %>% dplyr::count(building_type) %>% dplyr::arrange(desc(n)) %>% dplyr::mutate( building_type_1 = fct_reorder(building_type, n, "mean") ) ggplot(building, aes(x = building_type_1, y = n)) + geom_col() + coord_flip()
table(booking$booking_status) booking_time <- booking %>% dplyr::filter(booking_status == "completed") %>% dplyr::group_by(hour(booking_datetime)) %>% dplyr::count() colnames(booking_time) <- c("pickup_hour", "number") ggplot(booking_time, aes(x = pickup_hour, y = number)) + geom_line(size = 1,color = 'red') + geom_point(shape = 21, size = 2, stroke = 1.2, color = 'red', fill = 'white')
booking_month <- booking %>% dplyr::filter(booking_status == "completed") %>% dplyr::group_by(month(booking_datetime)) %>% dplyr::count() colnames(booking_month) <- c("pickup_month", "number") ggplot(booking_month, aes(x = as.factor(pickup_month), y = number)) + geom_col()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.