library(dplyr)
library(scales)
library(ggplot2)
library(extrafont)
library(lubridate)

Praproses Data

vids <- read.csv("USvideos.csv")
vids$trending_date <- ydm(vids$trending_date)

vids.daily <- vids %>% 
  group_by(trending_date) %>% 
  summarise(#nviews = sum(views),
            Likes = sum(likes),
            Dislikes = sum(dislikes),
            Comment = sum(comment_count)) %>% 
  tidyr::gather(category, value,2:4 ) %>% 
  mutate(trending_date = as.POSIXct.Date(trending_date))

Visualization Data using ggplot

create the main plot

youtube <- ggplot(vids.daily, aes(x = trending_date, y= value)) +
  geom_line(aes(linetype = category, col = category), size = 1.5)

youtube

add the axis scale and label to the plot

youtube <- youtube +
    scale_y_continuous(breaks = seq(0,15000000,by= 3000000), 
                       labels=function(x) format(x, big.mark = ",", scientific = FALSE)) +
    scale_x_datetime(breaks = date_breaks("1 week")) +
      labs(title = "Trending Youtube Traffic",
           subtitle = "From 13-Nov-2017 until 22-Jan-2018",
           caption = "Source: Kaggle dataset",
           tag = "Google LLC",
           x = "Tranding Date",
           y = "Total")

youtube

create my own theme

theme_youtube <- theme(panel.grid.minor = element_blank(),
          panel.grid.major.x = element_blank(),
          panel.grid.major.y = element_line(colour = "grey"),
          panel.background = element_rect(fill = "white"),
          axis.text.x = element_text(size = 12),
          axis.text.y = element_text(size = 15),
          axis.title = element_text(family = "Arial", size = 15),
          axis.ticks = element_line(colour = "grey"),
          plot.title = element_text(size = 25, face = "bold", colour = "#ff0000"),
          plot.subtitle = element_text(family = "Calibri", size = 15),
          plot.tag = element_text(colour = "#4285f4", face = "bold", size = 20),
          plot.caption = element_text(family = "Calibri", size = 15),
          legend.title = element_blank(),
          legend.position = "top",
          legend.justification = "left",
          legend.key = element_rect(fill = "white"),
          legend.key.size = unit(50, "pt"),
          legend.text = element_text(size = 15),
          legend.spacing.x = unit(10,"pt"),
          aspect.ratio = 1/2
          )

add my own theme (theme_youtube) to plot

youtube <- youtube + 
  theme_youtube

youtube

Interactive Plotting using Echart

library(echarts4r)
vids.daily %>% 
  group_by(category) %>% 
  e_charts(x = trending_date) %>%
  e_line(serie = value) %>% 
  e_tooltip(trigger = "axis") %>% 
  e_title(text = "Trending Youtube Traffic", 
          "From 13-Nov-2017 until 22-Jan-2018") %>% 
  e_theme(theme = "infographic") %>% 
  e_legend(right = 0) %>% 
  e_color(color = c("red", "green", "blue"), 
          background = "#FFFFFF") %>% 
  e_x_axis(name = "Trending Date") %>% 
  e_y_axis(name = "Total")