Pendahuluan

Halo Semuanya, salam kenal! Selamat datang di Rmd saya. Pada Rmd ini saya akan membahas suatu data yang berisikan tentang penjualan buku di salah satu online store yaitu Amazon Store dari tahun 2009 sampai tahun 2019. Dataset ini berisikan tujuh buah kolom yakni

  1. Name : berisikan nama dari buku
  2. Author : berisikan nama author atau penulis dari buku
  3. User rating : berisikan rating yang user berikan
  4. Reviews : berisikan banyaknya user yang mereviews buku
  5. Price : berisikan harga dari buku
  6. Year : berisikan tahun buku tersebut keluar
  7. Genre : berisikan genre dari buku

dari kolom-kolom Rmd ini akan membahas beberapa hal diantaranya :

  1. Bagaimana persebaran dari Genre buku di Amazon Store
  2. Bagaimana persebaran tahun buku-buku dikeluarkan
  3. 10 buku apa saja yang paling banyak direviews oleh user
  4. Siapa author yang merilis buku terbanyak
  5. Dari poin 4, buku apa saja yang telah author tersebut rilis dan bagaimana rating dari buku-buku tersebut

Data PreProcessing

Set Up

Sebelum kita melakukan eksplorasi, pertama-tama kita set up library yang akan kita gunakan pada Rmd ini.

library(dplyr)
## 
## 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)
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(glue)
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union

Import Data

Selanjutnya kita akan melakukan import/input data kedalam variabel books.

books <- read.csv("datainput/bestsellers with categories.csv")

Periksa Data

Kemudian lakukan pemeriksaan kepada kepala dan buntut dari data books.

head(books)
##                                                                 Name
## 1                                      10-Day Green Smoothie Cleanse
## 2                                                  11/22/63: A Novel
## 3                            12 Rules for Life: An Antidote to Chaos
## 4                                             1984 (Signet Classics)
## 5 5,000 Awesome Facts (About Everything!) (National Geographic Kids)
## 6                      A Dance with Dragons (A Song of Ice and Fire)
##                     Author User.Rating Reviews Price Year       Genre
## 1                 JJ Smith         4.7   17350     8 2016 Non Fiction
## 2             Stephen King         4.6    2052    22 2011     Fiction
## 3       Jordan B. Peterson         4.7   18979    15 2018 Non Fiction
## 4            George Orwell         4.7   21424     6 2017     Fiction
## 5 National Geographic Kids         4.8    7665    12 2019 Non Fiction
## 6      George R. R. Martin         4.4   12643    11 2011     Fiction
tail(books)
##                                                                                       Name
## 545                                                                                 Wonder
## 546                                           Wrecking Ball (Diary of a Wimpy Kid Book 14)
## 547 You Are a Badass: How to Stop Doubting Your Greatness and Start Living an Awesome Life
## 548 You Are a Badass: How to Stop Doubting Your Greatness and Start Living an Awesome Life
## 549 You Are a Badass: How to Stop Doubting Your Greatness and Start Living an Awesome Life
## 550 You Are a Badass: How to Stop Doubting Your Greatness and Start Living an Awesome Life
##            Author User.Rating Reviews Price Year       Genre
## 545 R. J. Palacio         4.8   21625     9 2017     Fiction
## 546   Jeff Kinney         4.9    9413     8 2019     Fiction
## 547   Jen Sincero         4.7   14331     8 2016 Non Fiction
## 548   Jen Sincero         4.7   14331     8 2017 Non Fiction
## 549   Jen Sincero         4.7   14331     8 2018 Non Fiction
## 550   Jen Sincero         4.7   14331     8 2019 Non Fiction

Ubah Tipe Data

Setelah itu kita periksa kembali apakah tipe data masing - masing kolom sudah sesuai, kalau belum maka diubah.

glimpse(books)
## Rows: 550
## Columns: 7
## $ Name        <chr> "10-Day Green Smoothie Cleanse", "11/22/63: A Novel", "12 …
## $ Author      <chr> "JJ Smith", "Stephen King", "Jordan B. Peterson", "George …
## $ User.Rating <dbl> 4.7, 4.6, 4.7, 4.7, 4.8, 4.4, 4.7, 4.7, 4.7, 4.6, 4.6, 4.6…
## $ Reviews     <int> 17350, 2052, 18979, 21424, 7665, 12643, 19735, 19699, 5983…
## $ Price       <int> 8, 22, 15, 6, 12, 11, 30, 15, 3, 8, 8, 2, 32, 5, 17, 4, 6,…
## $ Year        <int> 2016, 2011, 2018, 2017, 2019, 2011, 2014, 2017, 2018, 2016…
## $ Genre       <chr> "Non Fiction", "Fiction", "Non Fiction", "Fiction", "Non F…

Pada hal ini, terdapat kolom Author, dan Genre yang perlu dirubah menjadi tipe data faktor dan juga ubah kolom Year menjadi tipe data Datetime.

books <- books %>% mutate(Author = as.factor(Author), Genre = as.factor(Genre))
books$Year <- year(as.Date(as.character(books$Year),format = "%Y"))

Periksa kembali apakah sudah berubah.

glimpse(books)
## Rows: 550
## Columns: 7
## $ Name        <chr> "10-Day Green Smoothie Cleanse", "11/22/63: A Novel", "12 …
## $ Author      <fct> JJ Smith, Stephen King, Jordan B. Peterson, George Orwell,…
## $ User.Rating <dbl> 4.7, 4.6, 4.7, 4.7, 4.8, 4.4, 4.7, 4.7, 4.7, 4.6, 4.6, 4.6…
## $ Reviews     <int> 17350, 2052, 18979, 21424, 7665, 12643, 19735, 19699, 5983…
## $ Price       <int> 8, 22, 15, 6, 12, 11, 30, 15, 3, 8, 8, 2, 32, 5, 17, 4, 6,…
## $ Year        <dbl> 2016, 2011, 2018, 2017, 2019, 2011, 2014, 2017, 2018, 2016…
## $ Genre       <fct> Non Fiction, Fiction, Non Fiction, Fiction, Non Fiction, F…

Periksa Missing Value dan Duplicate

Sekarang kita periksa apakah books memiliki data yang terduplikat

sum(duplicated(books))
## [1] 0

periksa juga apakah books memiliki data yang missing.

colSums(is.na(books))
##        Name      Author User.Rating     Reviews       Price        Year 
##           0           0           0           0           0           0 
##       Genre 
##           0

#Data Exploratory Setelah melakukan preprocessing, kita akan melakukan exploratory. Pertama-tama kita ingin mendapatkan gambaran umum atau garis besar dari data kita.

summary(books)
##      Name                                          Author     User.Rating   
##  Length:550         Jeff Kinney                       : 12   Min.   :3.300  
##  Class :character   Gary Chapman                      : 11   1st Qu.:4.500  
##  Mode  :character   Rick Riordan                      : 11   Median :4.700  
##                     Suzanne Collins                   : 11   Mean   :4.618  
##                     American Psychological Association: 10   3rd Qu.:4.800  
##                     Dr. Seuss                         :  9   Max.   :4.900  
##                     (Other)                           :486                  
##     Reviews          Price            Year              Genre    
##  Min.   :   37   Min.   :  0.0   Min.   :2009   Fiction    :240  
##  1st Qu.: 4058   1st Qu.:  7.0   1st Qu.:2011   Non Fiction:310  
##  Median : 8580   Median : 11.0   Median :2014                    
##  Mean   :11953   Mean   : 13.1   Mean   :2014                    
##  3rd Qu.:17253   3rd Qu.: 16.0   3rd Qu.:2017                    
##  Max.   :87841   Max.   :105.0   Max.   :2019                    
## 

Berbekal dari summary tersebut kita dapat melakukan exploratory lebih lanjut dan menjawab pertanyaan-pertanyaan yang kita miliki.

1. Bagaimana persebaran dari Genre buku di Amazon Store

table(books$Genre)
## 
##     Fiction Non Fiction 
##         240         310
plot(books$Genre)

# d1 dipakai untuk melakukan visualisasi dengan ggplot
d1 <- books %>% group_by(Genre) %>% summarise(Banyak = n()) %>% ungroup()
d1 <- d1 %>% mutate(label = glue("{Genre}
                    Jumlah : {Banyak}"))

Jawaban: Data Genre tersebar pada dua kategori yaitu fiction dan non fiction dengan fiction sejumlah 240 dan non fiction 310.

2. Bagaimana persebaran tahun buku-buku dikeluarkan

table(books$Year)
## 
## 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 
##   50   50   50   50   50   50   50   50   50   50   50
hist(books$Year)

# d2 dipakai untuk melakukan visualisasi dengan ggplot
d2 <- books %>% group_by(Year, Genre) %>% summarise(Banyak = n()) %>% ungroup() %>% mutate(label = glue("{Genre}
                                                                                                        Tahun: {Year}
                                                                                                        Banyak: {Banyak}"))
## `summarise()` has grouped output by 'Year'. You can override using the
## `.groups` argument.

Jawaban: Tahun rilis dari buku-buku di amazon store tersebar rata dari tahun 2009 sampai 2019 dengan banyak buku yang rilis per tahunnya adalah sebanyak 50 buku.

3. 10 buku apa saja yang paling banyak direviews oleh user

# d3 dipakai untuk melakukan visualisasi dengan ggplot
d3 <- books %>% group_by(Name) %>% arrange(-Reviews) %>% head(10) %>% mutate(label = glue("Judul: {Name}
                                                                                          Author: {Author}
                                                                                          Tahun rilis: {Year}
                                                                                          Banyak Review: {Reviews}"))

d3
## # A tibble: 10 × 8
## # Groups:   Name [5]
##    Name                    Author    User.Rating Reviews Price  Year Genre label
##    <chr>                   <fct>           <dbl>   <int> <int> <dbl> <fct> <glu>
##  1 Where the Crawdads Sing Delia Ow…         4.8   87841    15  2019 Fict… Judu…
##  2 The Girl on the Train   Paula Ha…         4.1   79446    18  2015 Fict… Judu…
##  3 The Girl on the Train   Paula Ha…         4.1   79446     7  2016 Fict… Judu…
##  4 Becoming                Michelle…         4.8   61133    11  2018 Non … Judu…
##  5 Becoming                Michelle…         4.8   61133    11  2019 Non … Judu…
##  6 Gone Girl               Gillian …         4     57271    10  2012 Fict… Judu…
##  7 Gone Girl               Gillian …         4     57271    10  2013 Fict… Judu…
##  8 Gone Girl               Gillian …         4     57271     9  2014 Fict… Judu…
##  9 The Fault in Our Stars  John Gre…         4.7   50482    13  2012 Fict… Judu…
## 10 The Fault in Our Stars  John Gre…         4.7   50482    13  2013 Fict… Judu…

Jawaban: 10 buku yang paling banyak direviews oleh user diantaranya ada “Where the Crawdads Sings” karya Delia Owens, “The Girl on the Trains” karya Paula Hawkins yang keluar pada tahun 2015 dan tahun 2016, “Becoming” karya Michelle Obama, dan seterusnya.

4. Siapa author yang merilis buku terbanyak

# d4 dipakai untuk melakukan visualisasi dengan ggplot
d4 <- books %>% group_by(Author) %>% summarise(Banyak = n()) %>% ungroup() %>% arrange(-Banyak) %>% head(5) %>% 
mutate(label = glue("Penulis:{Author}
                    Banyak buku: {Banyak}"))
d4
## # A tibble: 5 × 3
##   Author                             Banyak label                               
##   <fct>                               <int> <glue>                              
## 1 Jeff Kinney                            12 Penulis:Jeff Kinney
## Banyak buku: 12  
## 2 Gary Chapman                           11 Penulis:Gary Chapman
## Banyak buku: 11 
## 3 Rick Riordan                           11 Penulis:Rick Riordan
## Banyak buku: 11 
## 4 Suzanne Collins                        11 Penulis:Suzanne Collins
## Banyak buku:…
## 5 American Psychological Association     10 Penulis:American Psychological Asso…

Jawaban: Author yang merilis buku terbanyak adalah Jeff Kinney

5. Dari poin 4, buku apa saja yang telah author tersebut rilis dan bagaimana rating dari buku-buku tersebut

# d5 dipakai untuk melakukan visualisasi dengan ggplot
d5 <- books %>%  filter(Author =="Jeff Kinney") %>% arrange(-User.Rating) %>% 
mutate(label = glue("Judul: {Name} 
Rating: {User.Rating} | Banyak Reviews: {Reviews}
Genre: {Genre}
Tahun rilis: {Year}"))
d5
##                                                  Name      Author User.Rating
## 1        Wrecking Ball (Diary of a Wimpy Kid Book 14) Jeff Kinney         4.9
## 2          Cabin Fever (Diary of a Wimpy Kid, Book 6) Jeff Kinney         4.8
## 3             Diary of a Wimpy Kid: Hard Luck, Book 8 Jeff Kinney         4.8
## 4       Diary of a Wimpy Kid: The Last Straw (Book 3) Jeff Kinney         4.8
## 5                 Diary of a Wimpy Kid: The Long Haul Jeff Kinney         4.8
## 6  Dog Days (Diary of a Wimpy Kid, Book 4) (Volume 4) Jeff Kinney         4.8
## 7              Double Down (Diary of a Wimpy Kid #11) Jeff Kinney         4.8
## 8               Old School (Diary of a Wimpy Kid #10) Jeff Kinney         4.8
## 9                                         The Getaway Jeff Kinney         4.8
## 10        The Meltdown (Diary of a Wimpy Kid Book 13) Jeff Kinney         4.8
## 11      The Ugly Truth (Diary of a Wimpy Kid, Book 5) Jeff Kinney         4.8
## 12     The Third Wheel (Diary of a Wimpy Kid, Book 7) Jeff Kinney         4.7
##    Reviews Price Year   Genre
## 1     9413     8 2019 Fiction
## 2     4505     0 2011 Fiction
## 3     6812     0 2013 Fiction
## 4     3837    15 2009 Fiction
## 5     6540    22 2014 Fiction
## 6     3181    12 2009 Fiction
## 7     5118    20 2016 Fiction
## 8     6169     7 2015 Fiction
## 9     5836     0 2017 Fiction
## 10    5898     8 2018 Fiction
## 11    3796    12 2010 Fiction
## 12    6377     7 2012 Fiction
##                                                                                                                                label
## 1        Judul: Wrecking Ball (Diary of a Wimpy Kid Book 14) \nRating: 4.9 | Banyak Reviews: 9413\nGenre: Fiction\nTahun rilis: 2019
## 2          Judul: Cabin Fever (Diary of a Wimpy Kid, Book 6) \nRating: 4.8 | Banyak Reviews: 4505\nGenre: Fiction\nTahun rilis: 2011
## 3             Judul: Diary of a Wimpy Kid: Hard Luck, Book 8 \nRating: 4.8 | Banyak Reviews: 6812\nGenre: Fiction\nTahun rilis: 2013
## 4       Judul: Diary of a Wimpy Kid: The Last Straw (Book 3) \nRating: 4.8 | Banyak Reviews: 3837\nGenre: Fiction\nTahun rilis: 2009
## 5                 Judul: Diary of a Wimpy Kid: The Long Haul \nRating: 4.8 | Banyak Reviews: 6540\nGenre: Fiction\nTahun rilis: 2014
## 6  Judul: Dog Days (Diary of a Wimpy Kid, Book 4) (Volume 4) \nRating: 4.8 | Banyak Reviews: 3181\nGenre: Fiction\nTahun rilis: 2009
## 7              Judul: Double Down (Diary of a Wimpy Kid #11) \nRating: 4.8 | Banyak Reviews: 5118\nGenre: Fiction\nTahun rilis: 2016
## 8               Judul: Old School (Diary of a Wimpy Kid #10) \nRating: 4.8 | Banyak Reviews: 6169\nGenre: Fiction\nTahun rilis: 2015
## 9                                         Judul: The Getaway \nRating: 4.8 | Banyak Reviews: 5836\nGenre: Fiction\nTahun rilis: 2017
## 10        Judul: The Meltdown (Diary of a Wimpy Kid Book 13) \nRating: 4.8 | Banyak Reviews: 5898\nGenre: Fiction\nTahun rilis: 2018
## 11      Judul: The Ugly Truth (Diary of a Wimpy Kid, Book 5) \nRating: 4.8 | Banyak Reviews: 3796\nGenre: Fiction\nTahun rilis: 2010
## 12     Judul: The Third Wheel (Diary of a Wimpy Kid, Book 7) \nRating: 4.7 | Banyak Reviews: 6377\nGenre: Fiction\nTahun rilis: 2012

Jawaban: Jeff Kinney telah merilis sebanyak 12 seperti “Wrecking Ball(Diary of a Wimpy Kid Book 14)” , “Cabin Fever (Diary of a Wimpy Kid, Book 6)” , “Diary of a Wimpy Kid: Hard Luck, Book 8”, dan seterusnya.

Visualisasi

Berikut merupakan visualisasi dengan ggplot untuk menjawab dari pertanyaan-pertanyaan diatas.

Persebaran Genre

plot1  <-  ggplot(d1, aes(x= Genre, y = Banyak, fill = Genre, text = label)) + geom_bar(stat="identity") + scale_fill_manual(values=c("#000000","#ff9900" )) + 
  labs(title = "Persebaran Genre buku pada Amazon Store",
       x = "Genre",
       y = NULL) +
  theme_minimal() +
  theme(legend.position = "none")
ggplotly(plot1 , tooltip = "text")

Persebaran Tahun Keluar

plot2 <- ggplot(d2, aes(x= Year, y=Banyak, fill = Genre, text = label)) +geom_bar(stat = "Identity", position = "dodge", color = "#000000") + scale_fill_manual(values=c("#f2f2f2","#ff9900" )) + labs(title = "Persebaran Tahun Keluar",
                                                                                    x = "Tahun",
                                                                                    y = NULL)+ theme_light() + theme(legend.position = "none") 
ggplotly(plot2, tooltip = "text")

10 Buku Paling Direview

plot3 <- ggplot(d3, aes(x = Reviews , y= reorder(1:nrow(d3), Reviews) , fill = Name, text = label)) + geom_bar(stat = "Identity", color = "#000000") +
  scale_fill_manual(values=c( "#f2f2f2", "#2DBFF8", "#08AAE3", "#E4C083", "#CEA968" )) + labs(title = "10 Buku Paling Direview",
                                                                                    x = "Reviewers",
                                                                                    y = "Judul") +
  theme_minimal() +theme(legend.position = "none") + scale_y_discrete(labels=d3$Name, breaks=rev(1:nrow(d3)), limits=rev(1:nrow(d3)),) + scale_x_continuous(labels = scales::comma) 
## Warning: Continuous limits supplied to discrete scale.
## ℹ Did you mean `limits = factor(...)` or `scale_*_continuous()`?
ggplotly(plot3, tooltip = "text")  

Penulis dengan Rilis Buku Terbanyak

plot4 <- ggplot(d4, aes(x= Banyak, y = reorder(Author,Banyak), fill = Author, text = label)) + geom_bar(stat = "Identity", color = "#000000") +
  scale_fill_manual(values=c( "#2DBFF8" ,"#146eb4",  "#ff9900", "#232f3e", "#f2f2f2" )) + labs(title = "Penulis dengan Rilis Buku Terbanyak",
                                                                                    x = "Banyak Buku",
                                                                                    y = NULL) +
  theme_minimal() +theme(legend.position = "none") 
ggplotly(plot4, tooltip = "text")

Rating Buku karangan Jeff Kinney

plot5 <- ggplot(d5, aes(x= User.Rating, y = reorder(Name,User.Rating), fill = Name, text = label)) + geom_bar(stat = "Identity", color = "#000000") + 
  theme_minimal() + theme(legend.position = "none") +
  scale_fill_manual(values = c("#E35335","#7DF9FF", "#228B22", "#FFAA33", "#FDDA0D" , "#FF2400", "#36454F", "#0047AB", "#800080",  "#B4C424", "#BF40BF",  "#818589"  )) +
labs(title = "Rating Buku Karangan Jeff Kinney", 
     x = "Rating",y = NULL)  
ggplotly(plot5, tooltip = "text")