This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
#khai báo thư viện
library("utils")
library("readxl") #đọc excel
#khai báo thư viện của ggplot2
library(ggplot2)
library(tidyverse)
library(ggthemes)
#chorddiag
install.packages("chorddiag")
install.packages("devtools")
devtools::install_github("mattflor/chorddiag", build_vignettes = TRUE)
library(chorddiag)
#mặc định
library("reshape2")
library("knitr") # tạo bảng
library("grid")
library("gridExtra") # vẽ nhiều đồ thị cùng lúc
library("kableExtra") # tạo bảng
library("naniar") # cho dữ liệu missing
library("mice") # điền các giá trị missing
library("rmarkdown")
# bar chart race
library("gganimate")
library("ggflags")
library("countrycode")
#đồ thị
ggplot(data = os, aes(x = delivery_charges,y = customer_long, fill = is_happy_customer, col = is_happy_customer)) + geom_point() +
labs(x = "order price", y = "coupon discount", title = "gia tri hang hoa mua theo mua") +
geom_smooth(method = "lm")
#đồ thị bar chart race
p_ani <- os %>%
drop_na(delivery_charges) %>%
count(nearest_warehouse, date) %>%
arrange (date, desc(n)) %>%
group_by(date) %>%
#mutate(Noc_2 = tolower(countrycode(nearest_warehouse, "iso3c", "iso2c"))) %>%
drop_na() %>%
mutate(rank = rank(order(n, decreasing = T))) %>%
arrange(date, rank) %>%
filter(date %in% 1:12) %>%
ggplot(aes(x = rank, y = n)) +
geom_col(fill = "azure3", color = "black", width = 0.7) +
geom_text(aes(y = 0, label = date, size = 5)) +
geom_text(aes(x = rank, y = 0, label = nearest_warehouse), size = 3) +
coord_flip(expand = F, clip = "off") +
scale_x_reverse(limits = c(10.5 , 0)) +
labs(x = "", title = "", y = "delivery_charges") +
theme(
panel.background = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.x = element_text(margin = margin(t = 20), face = "bold")
) +
transition_states(date, transition_length = 4, state_length = 1)
animate(p_ani, fps = 30, duration = 20, width = 700, height = 470, res = 120)