library(dplyr) # transformasi data
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2) # visualisasi
library(ggpubr)
library(scales) # untuk tampilan digit (memberikan koma dll)
library(glue)
library(plotly) 
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(lubridate) # working with datetime
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(tidyr)
options(scipen = 100) # supaya output tidak menampilkan notasi ilmiah (10-e10)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0     ✔ stringr 1.5.0
## ✔ purrr   1.0.2     ✔ tibble  3.2.1
## ✔ readr   2.1.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ readr::col_factor() masks scales::col_factor()
## ✖ purrr::discard()    masks scales::discard()
## ✖ plotly::filter()    masks dplyr::filter(), stats::filter()
## ✖ dplyr::lag()        masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(babynames)
library(viridis)
## Loading required package: viridisLite
## 
## Attaching package: 'viridis'
## 
## The following object is masked from 'package:scales':
## 
##     viridis_pal
library(hrbrthemes)
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
##       Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
##       if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
library(plotly)
insta <- read.csv("result_instagram.csv", stringsAsFactors = TRUE)
head(insta)
##                                    postUrl
## 1 https://www.instagram.com/p/Cv7Gzu4ylOL/
## 2 https://www.instagram.com/p/Cv7Gzu4ylOL/
## 3 https://www.instagram.com/p/Cv7Gzu4ylOL/
## 4 https://www.instagram.com/p/Cv7Gzu4ylOL/
## 5 https://www.instagram.com/p/Cv7Gzu4ylOL/
## 6 https://www.instagram.com/p/Cv7Gzu4ylOL/
##                                                                                                                                                                                                                                                                 description
## 1 Serah terima KRI Pulau Fani-731 dan KRI Pulau Fanildo-732 kepada TNI Angkatan Laut yang diterima oleh Kepala Staf Angkatan Laut (KSAL) Laksamana TNI Muhammad Ali disaksikan oleh Panglima TNI Laksamana TNI Yudo Margono di Dermaga Madura, Komando Armada II, Surabaya.
## 2 Serah terima KRI Pulau Fani-731 dan KRI Pulau Fanildo-732 kepada TNI Angkatan Laut yang diterima oleh Kepala Staf Angkatan Laut (KSAL) Laksamana TNI Muhammad Ali disaksikan oleh Panglima TNI Laksamana TNI Yudo Margono di Dermaga Madura, Komando Armada II, Surabaya.
## 3 Serah terima KRI Pulau Fani-731 dan KRI Pulau Fanildo-732 kepada TNI Angkatan Laut yang diterima oleh Kepala Staf Angkatan Laut (KSAL) Laksamana TNI Muhammad Ali disaksikan oleh Panglima TNI Laksamana TNI Yudo Margono di Dermaga Madura, Komando Armada II, Surabaya.
## 4 Serah terima KRI Pulau Fani-731 dan KRI Pulau Fanildo-732 kepada TNI Angkatan Laut yang diterima oleh Kepala Staf Angkatan Laut (KSAL) Laksamana TNI Muhammad Ali disaksikan oleh Panglima TNI Laksamana TNI Yudo Margono di Dermaga Madura, Komando Armada II, Surabaya.
## 5 Serah terima KRI Pulau Fani-731 dan KRI Pulau Fanildo-732 kepada TNI Angkatan Laut yang diterima oleh Kepala Staf Angkatan Laut (KSAL) Laksamana TNI Muhammad Ali disaksikan oleh Panglima TNI Laksamana TNI Yudo Margono di Dermaga Madura, Komando Armada II, Surabaya.
## 6 Serah terima KRI Pulau Fani-731 dan KRI Pulau Fanildo-732 kepada TNI Angkatan Laut yang diterima oleh Kepala Staf Angkatan Laut (KSAL) Laksamana TNI Muhammad Ali disaksikan oleh Panglima TNI Laksamana TNI Yudo Margono di Dermaga Madura, Komando Armada II, Surabaya.
##   commentCount likeCount            location locationId
## 1          179     55272 Surabaya, Indonesia     327191
## 2          179     55272 Surabaya, Indonesia     327191
## 3          179     55272 Surabaya, Indonesia     327191
## 4          179     55272 Surabaya, Indonesia     327191
## 5          179     55272 Surabaya, Indonesia     327191
## 6          179     55272 Surabaya, Indonesia     327191
##                    pubDate isSidecar  type
## 1 2023-08-14T11:35:41.000Z      true Photo
## 2 2023-08-14T11:35:41.000Z      true Photo
## 3 2023-08-14T11:35:41.000Z      true Photo
## 4 2023-08-14T11:35:41.000Z      true Photo
## 5 2023-08-14T11:35:41.000Z      true Photo
## 6 2023-08-14T11:35:41.000Z      true Photo
##                                                                                                 caption
## 1 Photo by Prabowo Subianto on August 14, 2023. May be an image of 4 people, military uniform and text.
## 2 Photo by Prabowo Subianto on August 14, 2023. May be an image of 4 people, military uniform and text.
## 3 Photo by Prabowo Subianto on August 14, 2023. May be an image of 4 people, military uniform and text.
## 4 Photo by Prabowo Subianto on August 14, 2023. May be an image of 4 people, military uniform and text.
## 5 Photo by Prabowo Subianto on August 14, 2023. May be an image of 4 people, military uniform and text.
## 6 Photo by Prabowo Subianto on August 14, 2023. May be an image of 4 people, military uniform and text.
##                          profileUrl username
## 1 https://www.instagram.com/prabowo  prabowo
## 2 https://www.instagram.com/prabowo  prabowo
## 3 https://www.instagram.com/prabowo  prabowo
## 4 https://www.instagram.com/prabowo  prabowo
## 5 https://www.instagram.com/prabowo  prabowo
## 6 https://www.instagram.com/prabowo  prabowo
##                                                                                                                                                                                                                                                                                                                            imgUrl
## 1  https://scontent-iad3-1.cdninstagram.com/v/t51.2885-15/366964611_1705625649913180_510540367359754577_n.jpg?stp=dst-jpg_e35_s1080x1080&_nc_ht=scontent-iad3-1.cdninstagram.com&_nc_cat=104&_nc_ohc=xAcDu9TaL9sAX-A_qiF&edm=AOQ1c0wBAAAA&ccb=7-5&oh=00_AfBO7zaAi9W_M7Y-vgqmowLGq0rOI_kYUR-I7AjWIh6nVw&oe=64DE95D2&_nc_sid=8b3546
## 2  https://scontent-iad3-1.cdninstagram.com/v/t51.2885-15/366943086_317191617377872_8092924750293261621_n.jpg?stp=dst-jpg_e35_s1080x1080&_nc_ht=scontent-iad3-1.cdninstagram.com&_nc_cat=104&_nc_ohc=fvuuHupLyV0AX-vSUtm&edm=AOQ1c0wBAAAA&ccb=7-5&oh=00_AfCbq70eL9ODVch5DnN7reH4KaphRNJqLeqI0kjSM8ekrw&oe=64DF56A2&_nc_sid=8b3546
## 3  https://scontent-iad3-1.cdninstagram.com/v/t51.2885-15/367348306_216265511069505_2741951753990197063_n.jpg?stp=dst-jpg_e35_s1080x1080&_nc_ht=scontent-iad3-1.cdninstagram.com&_nc_cat=109&_nc_ohc=PjfHvwRog68AX-azN33&edm=AOQ1c0wBAAAA&ccb=7-5&oh=00_AfBEqrPayO79E2V37DYSpnsic88JMECn71tOHyoqUjObog&oe=64DEC349&_nc_sid=8b3546
## 4  https://scontent-iad3-2.cdninstagram.com/v/t51.2885-15/367875199_299801042730927_4971619377639152400_n.jpg?stp=dst-jpg_e35_s1080x1080&_nc_ht=scontent-iad3-2.cdninstagram.com&_nc_cat=103&_nc_ohc=PQx6DyQt6c8AX-i6IQM&edm=AOQ1c0wBAAAA&ccb=7-5&oh=00_AfCnLtnc31ZHV-gCk7FJ1_dvhD2KwS0zcfZXTnxOgCzvkA&oe=64DE83B1&_nc_sid=8b3546
## 5  https://scontent-iad3-1.cdninstagram.com/v/t51.2885-15/366547465_678651920309704_5951227320945739949_n.jpg?stp=dst-jpg_e35_s1080x1080&_nc_ht=scontent-iad3-1.cdninstagram.com&_nc_cat=104&_nc_ohc=Bd3h0YSe8dEAX9agx0l&edm=AOQ1c0wBAAAA&ccb=7-5&oh=00_AfAvZf9aiiAP6Tm2hfIpWFWRlWZOsum9Lc7_98qW8s4IPw&oe=64DF3D92&_nc_sid=8b3546
## 6 https://scontent-iad3-1.cdninstagram.com/v/t51.2885-15/367452487_6496179507128270_3394560152408363905_n.jpg?stp=dst-jpg_e35_s1080x1080&_nc_ht=scontent-iad3-1.cdninstagram.com&_nc_cat=102&_nc_ohc=0yCyZCXnuv8AX_60Fdw&edm=AOQ1c0wBAAAA&ccb=7-5&oh=00_AfCy-sVWtvKJ9hIHBEr4Pjx8m5ZmWj1qOmRP2vOm08czZA&oe=64DF8BC5&_nc_sid=8b3546
##                postId                timestamp
## 1 3169156698284442403 2023-08-14T12:20:16.631Z
## 2 3169156698494042209 2023-08-14T12:20:16.631Z
## 3 3169156698292803557 2023-08-14T12:20:16.631Z
## 4 3169156698292662669 2023-08-14T12:20:16.631Z
## 5 3169156698292689060 2023-08-14T12:20:16.631Z
## 6 3169156698284406126 2023-08-14T12:20:16.631Z
##                                query taggedFullName1 taggedUsername1
## 1 https://www.instagram.com/prabowo/                                
## 2 https://www.instagram.com/prabowo/                                
## 3 https://www.instagram.com/prabowo/                                
## 4 https://www.instagram.com/prabowo/                                
## 5 https://www.instagram.com/prabowo/                                
## 6 https://www.instagram.com/prabowo/                                
##   taggedFullName2 taggedUsername2 taggedFullName3 taggedUsername3 videoUrl
## 1                                                                         
## 2                                                                         
## 3                                                                         
## 4                                                                         
## 5                                                                         
## 6                                                                         
##   viewCount likedByViewer fullName taggedFullName4 taggedUsername4
## 1        NA                                                       
## 2        NA                                                       
## 3        NA                                                       
## 4        NA                                                       
## 5        NA                                                       
## 6        NA                                                       
##   taggedFullName5 taggedUsername5 taggedFullName6 taggedUsername6
## 1                                                                
## 2                                                                
## 3                                                                
## 4                                                                
## 5                                                                
## 6                                                                
##   taggedFullName7 taggedUsername7 videoDuration playCount taggedFullName8
## 1                                            NA        NA                
## 2                                            NA        NA                
## 3                                            NA        NA                
## 4                                            NA        NA                
## 5                                            NA        NA                
## 6                                            NA        NA                
##   taggedUsername8 taggedFullName9 taggedUsername9 taggedFullName10
## 1                                                                 
## 2                                                                 
## 3                                                                 
## 4                                                                 
## 5                                                                 
## 6                                                                 
##   taggedUsername10 taggedFullName11 taggedUsername11 taggedFullName12
## 1                                                                    
## 2                                                                    
## 3                                                                    
## 4                                                                    
## 5                                                                    
## 6                                                                    
##   taggedUsername12 taggedFullName13 taggedUsername13 taggedFullName14
## 1                                                                    
## 2                                                                    
## 3                                                                    
## 4                                                                    
## 5                                                                    
## 6                                                                    
##   taggedUsername14 taggedFullName15 taggedUsername15 taggedFullName16
## 1                                                                    
## 2                                                                    
## 3                                                                    
## 4                                                                    
## 5                                                                    
## 6                                                                    
##   taggedUsername16 taggedFullName17 taggedUsername17 taggedFullName18
## 1                                                                    
## 2                                                                    
## 3                                                                    
## 4                                                                    
## 5                                                                    
## 6                                                                    
##   taggedUsername18 taggedFullName19 taggedUsername19 taggedFullName20
## 1                                                                    
## 2                                                                    
## 3                                                                    
## 4                                                                    
## 5                                                                    
## 6                                                                    
##   taggedUsername20
## 1                 
## 2                 
## 3                 
## 4                 
## 5                 
## 6
insta <- select(.data = insta,
       -isSidecar,
       -taggedFullName1,
       -taggedUsername1,
       -taggedFullName2,
       -taggedUsername2,
       -taggedFullName3,
       -taggedUsername3,
       -taggedFullName4,
       -taggedUsername4,
       -taggedFullName5,
       -taggedUsername5,
       -taggedFullName6,
       -taggedUsername6,
       -taggedFullName7,
       -taggedUsername7,
       -taggedFullName8,
       -taggedUsername8,
       -taggedFullName9,
       -taggedUsername9,
       -taggedFullName10,
       -taggedUsername10,
       -taggedFullName11,
       -taggedUsername11,
       -taggedFullName12,
       -taggedUsername12,
       -taggedFullName13,
       -taggedUsername13,
       -taggedFullName14,
       -taggedUsername14,
       -taggedFullName15,
       -taggedUsername15,
       -taggedFullName16,
       -taggedUsername16,
       -taggedFullName17,
       -taggedUsername17,
       -taggedFullName18,
       -taggedUsername18,
       -taggedFullName19,
       -taggedUsername19,
       -taggedFullName20,
       -taggedUsername20,
       -imgUrl,
       -videoUrl,
       -viewCount,
       -likedByViewer,
       -fullName,
       -videoDuration,
       -playCount,
       -timestamp,
       -locationId,
       -caption,
       -timestamp,
       -query)
insta$pubDate  <- ymd_hms(insta$pubDate, tz = "America/New_York")
## Date in ISO8601 format; converting timezone from UTC to "America/New_York".
glimpse(insta)
## Rows: 12,348
## Columns: 10
## $ postUrl      <fct> https://www.instagram.com/p/Cv7Gzu4ylOL/, https://www.ins…
## $ description  <fct> "Serah terima KRI Pulau Fani-731 dan KRI Pulau Fanildo-73…
## $ commentCount <int> 179, 179, 179, 179, 179, 179, 179, 179, 681, 681, 681, 68…
## $ likeCount    <int> 55272, 55272, 55272, 55272, 55272, 55272, 55272, 55272, 6…
## $ location     <fct> "Surabaya, Indonesia", "Surabaya, Indonesia", "Surabaya, …
## $ pubDate      <dttm> 2023-08-14 07:35:41, 2023-08-14 07:35:41, 2023-08-14 07:…
## $ type         <fct> Photo, Photo, Photo, Photo, Photo, Photo, Photo, Photo, P…
## $ profileUrl   <fct> https://www.instagram.com/prabowo, https://www.instagram.…
## $ username     <fct> prabowo, prabowo, prabowo, prabowo, prabowo, prabowo, pra…
## $ postId       <fct> 3169156698284442403, 3169156698494042209, 316915669829280…
insta$publish_month <- month(insta$pubDate)
insta$publish_day <- wday(insta$pubDate, label = T, abbr = F)
insta$publish_hour <- hour(insta$pubDate)
glimpse(insta)
## Rows: 12,348
## Columns: 13
## $ postUrl       <fct> https://www.instagram.com/p/Cv7Gzu4ylOL/, https://www.in…
## $ description   <fct> "Serah terima KRI Pulau Fani-731 dan KRI Pulau Fanildo-7…
## $ commentCount  <int> 179, 179, 179, 179, 179, 179, 179, 179, 681, 681, 681, 6…
## $ likeCount     <int> 55272, 55272, 55272, 55272, 55272, 55272, 55272, 55272, …
## $ location      <fct> "Surabaya, Indonesia", "Surabaya, Indonesia", "Surabaya,…
## $ pubDate       <dttm> 2023-08-14 07:35:41, 2023-08-14 07:35:41, 2023-08-14 07…
## $ type          <fct> Photo, Photo, Photo, Photo, Photo, Photo, Photo, Photo, …
## $ profileUrl    <fct> https://www.instagram.com/prabowo, https://www.instagram…
## $ username      <fct> prabowo, prabowo, prabowo, prabowo, prabowo, prabowo, pr…
## $ postId        <fct> 3169156698284442403, 3169156698494042209, 31691566982928…
## $ publish_month <dbl> 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,…
## $ publish_day   <ord> Monday, Monday, Monday, Monday, Monday, Monday, Monday, …
## $ publish_hour  <int> 7, 7, 7, 7, 7, 7, 7, 7, 22, 22, 22, 22, 7, 5, 1, 1, 1, 1…
insta$publish_date <- date(insta$pubDate)
glimpse(insta)
## Rows: 12,348
## Columns: 14
## $ postUrl       <fct> https://www.instagram.com/p/Cv7Gzu4ylOL/, https://www.in…
## $ description   <fct> "Serah terima KRI Pulau Fani-731 dan KRI Pulau Fanildo-7…
## $ commentCount  <int> 179, 179, 179, 179, 179, 179, 179, 179, 681, 681, 681, 6…
## $ likeCount     <int> 55272, 55272, 55272, 55272, 55272, 55272, 55272, 55272, …
## $ location      <fct> "Surabaya, Indonesia", "Surabaya, Indonesia", "Surabaya,…
## $ pubDate       <dttm> 2023-08-14 07:35:41, 2023-08-14 07:35:41, 2023-08-14 07…
## $ type          <fct> Photo, Photo, Photo, Photo, Photo, Photo, Photo, Photo, …
## $ profileUrl    <fct> https://www.instagram.com/prabowo, https://www.instagram…
## $ username      <fct> prabowo, prabowo, prabowo, prabowo, prabowo, prabowo, pr…
## $ postId        <fct> 3169156698284442403, 3169156698494042209, 31691566982928…
## $ publish_month <dbl> 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,…
## $ publish_day   <ord> Monday, Monday, Monday, Monday, Monday, Monday, Monday, …
## $ publish_hour  <int> 7, 7, 7, 7, 7, 7, 7, 7, 22, 22, 22, 22, 7, 5, 1, 1, 1, 1…
## $ publish_date  <date> 2023-08-14, 2023-08-14, 2023-08-14, 2023-08-14, 2023-08…
insta <- insta %>% distinct(description, .keep_all = TRUE) %>% 
  filter(between(publish_date, as.Date('2022-01-01'), as.Date('2022-12-31')))
insta <- insta[insta$username %in% c("prabowo", "aniesbaswedan", "ganjar_pranowo"),]
glimpse(insta)
## Rows: 1,990
## Columns: 14
## $ postUrl       <fct> https://www.instagram.com/p/Cmy3xzcPbvJ/, https://www.in…
## $ description   <fct> "Suasana silaturahmi akhir tahun di Banyuwangi, Jawa Tim…
## $ commentCount  <int> 226, 468, 210, 841, 228, 651, 1122, 451, 305, 215, 134, …
## $ likeCount     <int> 21053, 35714, 30139, 50809, 20505, 30185, 136166, 38191,…
## $ location      <fct> "Banyuwangi, Jawa Timur, Indonesia", "SKADRON 17 - Halim…
## $ pubDate       <dttm> 2022-12-30 09:07:52, 2022-12-28 10:19:54, 2022-12-28 09…
## $ type          <fct> Photo, Photo, Photo, Photo, Photo, Photo, Photo, Photo, …
## $ profileUrl    <fct> https://www.instagram.com/prabowo, https://www.instagram…
## $ username      <fct> prabowo, prabowo, prabowo, prabowo, prabowo, prabowo, pr…
## $ postId        <fct> 3004709210777534196_2142213578, 3003295917798979261_2142…
## $ publish_month <dbl> 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, …
## $ publish_day   <ord> Friday, Wednesday, Wednesday, Tuesday, Tuesday, Sunday, …
## $ publish_hour  <int> 9, 10, 9, 18, 7, 22, 8, 23, 19, 5, 6, 23, 6, 6, 19, 10, …
## $ publish_date  <date> 2022-12-30, 2022-12-28, 2022-12-28, 2022-12-27, 2022-12…
anies_2022 <- filter(insta, username == "aniesbaswedan")
glimpse(anies_2022)
## Rows: 459
## Columns: 14
## $ postUrl       <fct> https://www.instagram.com/p/Cm3AgPuSppY/, https://www.in…
## $ description   <fct> "Beberapa hari yang lalu mampir ke Bandung sebentar, ber…
## $ commentCount  <int> 448, 204, 1660, 1554, 1565, 775, 1265, 693, 365, 366, 58…
## $ likeCount     <int> 35075, 10661, 55658, 97860, 104905, 24064, 97381, 39556,…
## $ location      <fct> "Celah~celah Lang!t", "", "Jakarta, Indonesia", "Pasar G…
## $ pubDate       <dttm> 2022-12-31 23:41:05, 2022-12-31 18:30:26, 2022-12-27 22…
## $ type          <fct> Photo, Photo, Video, Photo, Photo, Photo, Photo, Photo, …
## $ profileUrl    <fct> https://www.instagram.com/aniesbaswedan, https://www.ins…
## $ username      <fct> aniesbaswedan, aniesbaswedan, aniesbaswedan, aniesbaswed…
## $ postId        <fct> 3005873485303700019_550068236, 3005717140171632096_55006…
## $ publish_month <dbl> 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, …
## $ publish_day   <ord> Saturday, Saturday, Tuesday, Monday, Sunday, Saturday, T…
## $ publish_hour  <int> 23, 18, 22, 0, 2, 21, 3, 8, 7, 21, 20, 22, 5, 7, 22, 0, …
## $ publish_date  <date> 2022-12-31, 2022-12-31, 2022-12-27, 2022-12-26, 2022-12…
prabowo_2022 <- filter(insta, username == "prabowo")
glimpse(prabowo_2022)
## Rows: 166
## Columns: 14
## $ postUrl       <fct> https://www.instagram.com/p/Cmy3xzcPbvJ/, https://www.in…
## $ description   <fct> "Suasana silaturahmi akhir tahun di Banyuwangi, Jawa Tim…
## $ commentCount  <int> 226, 468, 210, 841, 228, 651, 1122, 451, 305, 215, 134, …
## $ likeCount     <int> 21053, 35714, 30139, 50809, 20505, 30185, 136166, 38191,…
## $ location      <fct> "Banyuwangi, Jawa Timur, Indonesia", "SKADRON 17 - Halim…
## $ pubDate       <dttm> 2022-12-30 09:07:52, 2022-12-28 10:19:54, 2022-12-28 09…
## $ type          <fct> Photo, Photo, Photo, Photo, Photo, Photo, Photo, Photo, …
## $ profileUrl    <fct> https://www.instagram.com/prabowo, https://www.instagram…
## $ username      <fct> prabowo, prabowo, prabowo, prabowo, prabowo, prabowo, pr…
## $ postId        <fct> 3004709210777534196_2142213578, 3003295917798979261_2142…
## $ publish_month <dbl> 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, …
## $ publish_day   <ord> Friday, Wednesday, Wednesday, Tuesday, Tuesday, Sunday, …
## $ publish_hour  <int> 9, 10, 9, 18, 7, 22, 8, 23, 19, 5, 6, 23, 6, 6, 19, 10, …
## $ publish_date  <date> 2022-12-30, 2022-12-28, 2022-12-28, 2022-12-27, 2022-12…
ganjar_2022 <- filter(insta, username == "ganjar_pranowo")
glimpse(ganjar_2022)
## Rows: 1,365
## Columns: 14
## $ postUrl       <fct> https://www.instagram.com/p/Cm24h8RBN_3/, https://www.in…
## $ description   <fct> "Celana robek, tutorial tinggi, hati terluka oleh mantan…
## $ commentCount  <int> 1880, 61, 446, 302, 865, 1757, 843, 360, 398, 113, 368, …
## $ likeCount     <int> 110461, 3966, 27411, 28876, 8403, 89388, 84171, 11696, 4…
## $ location      <fct> "", "", "", "", "", "", "", "", "", "", "", "", "", "", …
## $ pubDate       <dttm> 2022-12-31 22:34:03, 2022-12-31 21:51:20, 2022-12-31 20…
## $ type          <fct> Video, Photo, Video, Video, Video, Video, Photo, Video, …
## $ profileUrl    <fct> https://www.instagram.com/ganjar_pranowo, https://www.in…
## $ username      <fct> ganjar_pranowo, ganjar_pranowo, ganjar_pranowo, ganjar_p…
## $ postId        <fct> 3005838424373780471_2254554032, 3005818252032487452_2254…
## $ publish_month <dbl> 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, …
## $ publish_day   <ord> Saturday, Saturday, Saturday, Saturday, Saturday, Saturd…
## $ publish_hour  <int> 22, 21, 20, 12, 9, 4, 1, 8, 4, 8, 0, 21, 7, 5, 0, 21, 7,…
## $ publish_date  <date> 2022-12-31, 2022-12-31, 2022-12-31, 2022-12-31, 2022-12…
daily_like_total <- insta %>% 
  group_by(publish_date) %>% 
  summarise(
    likes = sum(likeCount),
    comments = sum(commentCount)
  ) %>% 
  ungroup()
daily_like_total
## # A tibble: 365 × 3
##    publish_date  likes comments
##    <date>        <int>    <int>
##  1 2022-01-01   526056    25953
##  2 2022-01-02   476256     6250
##  3 2022-01-03   316787     3762
##  4 2022-01-04   436268     8698
##  5 2022-01-05   337251     7135
##  6 2022-01-06   133447     1867
##  7 2022-01-07   485375    10978
##  8 2022-01-08   310785     6910
##  9 2022-01-09   735798     9461
## 10 2022-01-10   109445     1514
## # ℹ 355 more rows
overall_plot <- daily_like_total %>% 
  ggplot(aes(x=publish_date, y=likes)) +
  geom_line(color="black") +
  ggtitle("Daily Like Total") +
  ylab("Total Like") +
  theme_ipsum()
overall_plot

ggplotly(overall_plot)
total_engagement <- insta %>% 
  group_by(username) %>% 
  summarise(
    likes = sum(likeCount),
    comments = sum(commentCount)
  ) %>% 
  ungroup()
total_engagement
## # A tibble: 3 × 3
##   username          likes comments
##   <fct>             <int>    <int>
## 1 aniesbaswedan  28795042   751708
## 2 ganjar_pranowo 58393704   965301
## 3 prabowo         7563597    78202
engagement_pivot <- total_engagement %>% 
  pivot_longer(cols = c(likes, comments),
               names_to = "variable",
               values_to = "total_engagement")
engagement_pivot
## # A tibble: 6 × 3
##   username       variable total_engagement
##   <fct>          <chr>               <int>
## 1 aniesbaswedan  likes            28795042
## 2 aniesbaswedan  comments           751708
## 3 ganjar_pranowo likes            58393704
## 4 ganjar_pranowo comments           965301
## 5 prabowo        likes             7563597
## 6 prabowo        comments            78202
plot1 <- ggplot(data = engagement_pivot, aes(x = total_engagement, y = reorder(username, total_engagement))) +
  geom_col(aes(fill = variable), position="dodge")
plot1

ggplotly(plot1)
posting_freq <- insta %>% 
  group_by(username) %>% 
  summarise(count = n()) %>% 
  ungroup() %>% 
  arrange(-count)
  
posting_freq
## # A tibble: 3 × 2
##   username       count
##   <fct>          <int>
## 1 ganjar_pranowo  1365
## 2 aniesbaswedan    459
## 3 prabowo          166
plot2 <- ggplot(insta, aes(x=username, y=publish_date, fill=username)) + 
  geom_violin()
plot2

ggplotly(plot2)
most_commented <- insta %>% 
  group_by(username) %>% 
  summarise(avg_comment = mean(commentCount)) %>% 
  ungroup() %>% 
  mutate(
    label = glue("User Name: {username}
                 Average Comment: {avg_comment}")
  )
most_commented
## # A tibble: 3 × 3
##   username       avg_comment label                                              
##   <fct>                <dbl> <glue>                                             
## 1 aniesbaswedan        1638. User Name: aniesbaswedan
## Average Comment: 1637.7080…
## 2 ganjar_pranowo        707. User Name: ganjar_pranowo
## Average Comment: 707.1802…
## 3 prabowo               471. User Name: prabowo
## Average Comment: 471.096385542169
# plot 
plot3 <- ggplot(most_commented, 
                aes(x = as.factor(username), 
                    y = avg_comment,
                    text = label))+
  geom_line(col = "blue", group = 1) +
  geom_point(col = "red") +
  scale_y_continuous(labels = comma) +
  labs(
    title = "Most Commented Instagram Post",
    x = "Instagram Post",
    y = "Average Comments"
  ) +
  theme_minimal()

plot3

ggplotly(plot3, tooltip = "text")