Skip to content

Commit

Permalink
change colour ala gojek
Browse files Browse the repository at this point in the history
  • Loading branch information
akherlan committed Aug 31, 2021
1 parent 37fabfc commit fd7e999
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 39 deletions.
12 changes: 8 additions & 4 deletions 2-clock.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Email: andi.herlan@protonmail.com
# Data Used: gojek.rds
# Packages Used: dplyr, lubridate, ggplot2, gridExtra
# Source: colours.R
# Output File: clock.png
# Data Output: -
# Reference: https://www.wjakethompson.com/post/2018-11-27-ggclock/
Expand All @@ -16,6 +17,9 @@ library(lubridate)
library(ggplot2)
library(gridExtra)

# import colour definition
source("colours.R")

# main data
gojek <- readRDS("output/gojek.rds")

Expand Down Expand Up @@ -56,10 +60,10 @@ p1 <- ggplot(data = clock) +
label = paste0("Total\n", total_time, " hours\non the road")) +
# ride
geom_segment(aes(x, y, xend = x + 1, yend = y + 0.8),
colour = "#00AA13", alpha = 0.4) +
colour = gc_green50, alpha = 0.4) +
# car
geom_point(data = filter(clock, clock$col == "Car"),
aes(x, y), colour = "#000000", alpha = 0.8) +
aes(x, y), colour = "black", alpha = 0.8) +
# coordinate
coord_polar() +
expand_limits(y = c(-1, 1)) +
Expand All @@ -68,7 +72,7 @@ p1 <- ggplot(data = clock) +
labels = c(3, 6, 9, "12")) +
# text
labs(title = "Time with GOJEK", x = NULL, y = NULL,
subtitle = paste("Andi's movement in",
subtitle = paste("Movement in",
min(year(gojek$datetime)), "-",
max(year(gojek$datetime)), "(• is GoCar)", sep = " "),
caption = paste0("Last movement at ", tail(gojek$datetime, 1),
Expand Down Expand Up @@ -97,7 +101,7 @@ p2 <- ggplot(data = dura) +
label = paste0("~", round(duration/3600), " hours")),
size = 2.8, colour = "gray60", hjust = "left") +
geom_linerange(aes(xmin = x0, xmax = x1, y = year),
size = 4.6, alpha = 0.5, colour = "#00AA13") +
size = 4.6, alpha = 0.5, colour = gc_green50) +
scale_x_continuous(limits = c(0, limit_x_max)) +
labs(title = "Duration per year",
caption = "Github: akherlan | Data: GOJEK") +
Expand Down
16 changes: 10 additions & 6 deletions 3-distance.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Email: andi.herlan@protonmail.com
# Data Used: gojek.rds, java.rds
# Packages Used: dplyr, mapboxapi, ggplot2, ggrepel, gridExtra
# Source: colours.R
# Output File: distance.png
# Data Output: -
# Reference: https://ggplot2-book.org/annotations.html
Expand All @@ -18,6 +19,9 @@ library(ggplot2)
library(ggrepel)
library(gridExtra)

# import colour definition
source("colours.R")

# main data
gojek <- readRDS("output/gojek.rds")

Expand Down Expand Up @@ -76,7 +80,7 @@ p1 <- ggplot(data = distn) +
colour = "gray50") +
# late for the last train
annotate(geom = "point", x = latetrain$duration/60, alpha = 0.3,
y = latetrain$distance, size = 4, col = "orange") +
y = latetrain$distance, size = 4, col = gc_orange) +
annotate(geom = "curve", x = 50, y = 17, size = 0.3, col = "gray50",
xend = latetrain$duration/60+0.6, yend = latetrain$distance,
curvature = 0.3, arrow = arrow(length = unit(2, "mm"))) +
Expand All @@ -89,7 +93,7 @@ p1 <- ggplot(data = distn) +
size = 3, col = "gray50") +
# resettlement
annotate(geom = "point", x = comeback$duration/60, alpha = 0.3,
y = comeback$distance, size = 4, col = "orange") +
y = comeback$distance, size = 4, col = gc_orange) +
annotate(geom = "curve", x = 62, y = 25, size = 0.3, col = "gray50",
xend = comeback$duration/60-0.2, yend = comeback$distance-0.4,
curvature = 0.3, arrow = arrow(length = unit(2, "mm"))) +
Expand All @@ -107,7 +111,7 @@ p1 <- ggplot(data = distn) +
# scales
scale_y_continuous(breaks = seq(0, 30, 5)) +
scale_x_continuous(limits = c(0, 75), breaks = c(seq(0, 15, 5), 30, 45, 60, 75)) +
scale_colour_manual(values = c("#000000", "#00AA13")) +
scale_colour_manual(values = c("black", gc_green70)) +
# main labels
labs(
title = "Movement with GOJEK",
Expand All @@ -134,7 +138,7 @@ p1 <- ggplot(data = distn) +
# duration density
dx <- ggplot(dens) +
geom_density(aes(x = duration/60, y = -..density..),
fill = "lightblue", colour = "gray35", alpha = 0.5) +
fill = gc_green20, colour = "gray35", alpha = 0.5) +
labs(x = "Duration (minutes)", caption = "Github: akherlan | Data: GOJEK") +
scale_x_continuous(limits = c(0, 75), breaks = c(seq(0, 15, 5), 30, 45, 60, 75)) +
theme_minimal() +
Expand All @@ -154,7 +158,7 @@ dx <- ggplot(dens) +
# distance density
dy <- ggplot(dens) +
geom_density(aes(x = -..density.., y = distance),
fill = "lightblue", colour = "gray35", alpha = 0.5) +
fill = gc_green20, colour = "gray35", alpha = 0.5) +
scale_y_continuous(breaks = seq(0, 30, 5)) +
labs(y = "Distance (km)", title = " ", subtitle = " ") +
theme_minimal() +
Expand All @@ -178,7 +182,7 @@ p2 <- ggplot(java) +
geom_sf(data = odline, colour = "black", size = 0.5, linetype = 2) +
# location
geom_point(data = od, aes(long, lat),
colour = "red", size = 2, alpha = 0.6) +
colour = gc_red, size = 2, alpha = 0.6) +
coord_sf() +
theme_void()

Expand Down
55 changes: 36 additions & 19 deletions 4-cost.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Email: andi.herlan@protonmail.com
# Data Used: gojek.rds
# Packages Used: dplyr, tidyr, stringr, ggplot2
# Source: colours.R
# Output File: cost.png
# Data Output: -
# Reference: https://stackoverflow.com/questions/46597278/
Expand All @@ -11,17 +12,21 @@
# clear environment
rm(list = ls())

# import colour definition
source("colours.R")

library(dplyr)
library(tidyr)
library(stringr)
library(ggplot2)

# main data
gojek <- readRDS("output/gojek.rds")
gojek <- readRDS("output/gojek.rds") %>%
select(datetime, payment, price, discount, fee, paid)

# data for cost
# data for cost (rupiah in thousands)
cost <- gojek %>%
select(payment, price, discount, fee, paid) %>%
select(-datetime) %>%
pivot_longer(cols = 2:5, names_to = "type", values_to = "rupiah") %>%
group_by(payment, type) %>%
summarise(rupiah = sum(rupiah/1000), .groups = "drop") %>%
Expand All @@ -33,23 +38,21 @@ cost <- gojek %>%
# all discount
disc_total <- cost %>% group_by(type) %>% summarise(sum = sum(rupiah))

# discount in app
# discount, fee, price + fee in app
godisc <- cost$rupiah[5]
gofee <- cost$rupiah[6]
goprice <- round((cost$rupiah[8] + gofee)/1000, 2) # in millions IDR

# price + fee in app
fee <- cost$rupiah[6] # thousands
goprice <- round((cost$rupiah[8] + fee)/1000, 2) # millions

# percent cash expenses
# percent cash expenses between cash and gopay
paid_percent <- cost[cost$type == "Paid",] %>%
mutate(percent = round((rupiah/sum(rupiah))*100, 2))

# percent cost (price + fee in both cahs and gopay)
# percent cost (price + fee) in both cash and gopay
cost_percent <- cost %>%
filter(cat == 1) %>%
mutate(percent = round((rupiah/sum(rupiah))*100, 2))

# percent transactions done in app
# transactions done in app and cash
n_trans <- gojek %>%
select(paid, payment) %>%
group_by(payment) %>%
Expand All @@ -59,7 +62,17 @@ n_trans <- gojek %>%
# text postion transaction done in app
y_trans <- (cost$rupiah[5] + cost$rupiah[7])*2/3

# plot for costs
# cost_growth <- gojek %>%
# pivot_longer(cols = 3:6, names_to = "type", values_to = "rupiah") %>%
# group_by(type) %>%
# summarise(datetime = datetime,
# cumsum = cumsum(rupiah), .groups = "drop") %>%
# arrange(datetime)
#
# ggplot(cost_growth) +
# geom_line(aes(datetime, cumsum, colour = type), show.legend = F)

# plot for cost
ggplot() +
# bar price + fee
geom_bar(data = filter(cost, cat == 1),
Expand All @@ -73,7 +86,8 @@ ggplot() +
geom_text(data = filter(cost, cat == 1 & payment == "Cash"),
aes(x = 0, y = paid_percent$rupiah[1]/2,
label = paste0(paid_percent$percent[1], "%\nof expenses")),
size = 4, colour = "#B3E7F3") +
# size = 4, colour = "#B3E7F3") +
size = 4, colour = "#DEF5FD") +
# text price of all cost percent cash
geom_text(data = filter(cost, cat == 1 & payment == "Cash"),
aes(x = 1, y = cost_percent$rupiah[2]/2,
Expand All @@ -84,17 +98,19 @@ ggplot() +
aes(x = 0, y = paid_percent$rupiah[2]/2,
label = paste0(paid_percent$percent[2], "%\nof expenses\n(IDR ",
paid_percent$rupiah[2], ",000)")),
size = 4, colour = "#B3E7F3") +
# size = 4, colour = "#B3E7F3") +
size = 4, colour = "#DEF5FD") +
# text discount gopay
geom_text(data = filter(cost, cat == 1 & payment == "GoPay"),
aes(x = 0, y = cost$rupiah[7] + cost$rupiah[5]/2,
label = paste0("IDR ", godisc, ",000")),
size = 4, colour = "#00BBE0") +
# size = 4, colour = "#00BBE0") +
size = 4, colour = "#388192") +
# text price gopay
geom_text(data = filter(cost, cat == 1 & payment == "GoPay"),
aes(x = 1, y = cost$rupiah[8]/2,
label = paste0("Total costs\n IDR ", goprice,
" millions\n(include IDR ", fee,
" millions\n(include IDR ", gofee,
",000\nof additional app fee,\nparking, toll, etc.)\nwere paid inside app\nwith IDR ",
godisc, ",000\ndiscount+voucher")),
size = 3.4, colour = "#005400") +
Expand All @@ -113,7 +129,8 @@ ggplot() +
caption = "Github: akherlan | Data: GOJEK") +
# styling
facet_wrap(~payment, strip.position = "bottom") +
scale_fill_manual(values = c("#B3E7F3", "#000000", "#00BBE0", "#00AE00")) +
# scale_fill_manual(values = c("#B3E7F3", "#000000", "#00BBE0", "#00AE00")) +
scale_fill_manual(values = c("lightblue", "black", gc_blue, gc_green50)) +
theme_minimal() +
theme(
text = element_text(family = "Sans"),
Expand All @@ -123,7 +140,7 @@ ggplot() +
plot.subtitle = element_text(colour = "gray40"),
plot.caption = element_text(colour = "gray60"),
plot.title.position = "plot",
strip.text = element_text(face = "bold", size = 11),
strip.text = element_text(face = "bold", size = 11, colour = "gray40"),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
Expand All @@ -136,4 +153,4 @@ ggplot() +

# save PNG
ggsave("cost.png", path = "figs", dpi = 150, units = "px",
width = 2*756, height = 2*509)
width = 2*600, height = 2*469)
18 changes: 9 additions & 9 deletions 5-needs.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# Email: andi.herlan@protonmail.com
# Data Used: gojek.rds
# Packages Used: dplyr, tidyr, stringr, ggplot2, ggalluvial
# Source: colours.R
# Output File: needs.png
# Data Output: od.rds
# Reference: https://corybrunson.github.io/ggalluvial


# clear environment
rm(list = ls())

Expand All @@ -17,6 +17,9 @@ library(stringr)
library(ggplot2)
library(ggalluvial)

# import colour definition
source("colours.R")

# main data
gojek <- readRDS("output/gojek.rds")

Expand Down Expand Up @@ -92,9 +95,6 @@ od <- od %>%
!is.na(home), NA, TRUE))))
)

# empty category
nrow(od) - colSums(!is.na(od[,4:8])) %>% as.matrix() %>% sum()

# odplot <- od %>%
# select(-datetime) %>%
# mutate(count = 1) %>%
Expand Down Expand Up @@ -148,12 +148,13 @@ odp$destination <- odp$destination %>%
# plot
ggplot(data = odp,
aes(axis1 = origin, axis2 = destination, y = freq)) +
scale_x_discrete(limits = c("Origin", "Needs"),
expand = c(0, 0.2, 0, 0.7)) +
geom_alluvium(aes(fill = payment)) +
geom_stratum() +
geom_stratum(colour = "gray40") +
geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
scale_fill_manual(values = c("orange", "#00BBE0"),
scale_x_discrete(limits = c("Origin", "Needs"),
expand = c(0, 0.2, 0, 0.7)) +
# scale_fill_manual(values = c("orange", "#00BBE0"),
scale_fill_manual(values = c(gc_orange, gc_blue),
label = c("Cash", "GoPay")) +
annotate(geom = "text", x = 2.25, y = 190,
label = paste("The most frequence trip",
Expand Down Expand Up @@ -188,7 +189,6 @@ ggplot(data = odp,
legend.position = c(0.75, 0.85),
legend.direction = "vertical",
legend.justification = "left",
# panel.border = element_rect(colour = "black", size = 1, fill = "transparent", linetype = 2),
plot.title.position = "plot",
plot.subtitle = element_text(colour = "gray40"),
plot.caption = element_text(colour = "gray60"),
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Biaya ini belum termasuk dengan penggunaan GoTagihan (GoBills) untuk BPJS, pulsa

Perjalanan terbanyak ketika ng-Gojek adalah dari stasiun (atau halte) untuk pulang, disusul oleh perjalanan pulang selepas beraktivitas di luar selain kerja.

Ada hubungan yang erat antara kantor dengan aktivitas transit.
Ada hubungan yang erat antara kantor dengan aktivitas transit, dihubungkan dengan aktivitas ng-Gojek.

Jika saya harus menggunakan uang tunai kemungkinan karena saya kehabisan GoPay saat berada di luar rumah.

Expand Down
20 changes: 20 additions & 0 deletions colours.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Title: Colour Definition
# Author: Andi Herlan
# Email: andi.herlan@protonmail.com
# Reference https://www.gojek.com/data/

# use source("colours.R") in any script for graphic generating

"#006C0C" -> gc_green70
"#00AA13" -> gc_green50 # goride
"#4CC359" -> gc_green20
"#101820" -> gc_grayd # dark
"#727272" -> gc_grayl # light-dark
"#CACCCF" -> gc_black
"#E8E8E8" -> gc_black10
"#00AED6" -> gc_blue # gopay
"#772583" -> gc_purple # gobiz
"#BE1F2C" -> gc_red70
"#EE2737" -> gc_red # gofood
"#DF1995" -> gc_pink # goplay
"#F06400" -> gc_orange
Binary file modified figs/clock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/cost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/distance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/distance_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/needs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fd7e999

Please sign in to comment.