# Load packages
library(tidyverse)
library(ggplot2)
library(dplyr)
library(broom)
# Read in the dataset (from the url or directly from the file in your folder)
books = read.csv("http://www.maths.usyd.edu.au/u/UG/JM/DATA1001/r/current/projects/2022data/books.csv")
disease = read.csv("http://www.maths.usyd.edu.au/u/UG/JM/DATA1001/r/current/projects/2022data/disease.csv")
avocado = read.csv("http://www.maths.usyd.edu.au/u/UG/JM/DATA1001/r/current/projects/2022data/avocado.csv")
Client: Dymocks (https://www.dymocks.com.au/)
Dymocks, an Australian-founded bookstore chain request for the data
analysis to guide the selection of books that will increase their sales.
Based on the evidence presented in this report, Dymocks should take into
account the number of pages when selecting books to sell, since this
greatly impacts the books’ popularity.
books$average_rating <- as.numeric(books$average_rating)
books$num_pages <- as.numeric(books$num_pages)
books <- na.omit(books)
books <- books[order(books$ratings_count),]
plot1 <- ggplot(books, aes(x = num_pages, y = average_rating, color = ratings_count)) +
geom_point(size=1.2)+
geom_smooth(formula = y ~ x, method='lm',color="#003399")+
scale_colour_gradient2(low = "#F9A825",
midpoint = 1.3e+6,
mid = "white",
high = "#4C01B2") +
guides(color = guide_colorbar(title = "Number of Ratings"))+
theme(panel.background = element_rect(fill = '#F7F7F7'))
plot1 <- plot1 + ggtitle("Relationship Between Books's Average Rating and Number of Pages") +
xlab("Number of Pages") + ylab("Average Rating")
plot1 <- plot1 + theme(plot.title=element_text(size=15))
plot1
Figure 1. Plot of the relationship between average rating of books and the number of pages, with a linear regression line to show the relationship and colored by the number of ratings for each data point.
Based on Figure 1, there is a positive correlation between the average rating and the number of pages in a book, meaning that a book with more pages is more likely to receive higher ratings. As a result of their previous positive experience, they have a greater chance of recommend it to others or purchase another book from Dymocks in the future. On the other hand, the number of ratings, represented by colors on the plot, did not seem to correlate with average rating. In other words, even if a book receives more ratings, it doesn’t necessarily mean that it is popular or well-liked by the readers.
However, while a positive linear regression line was visible in Figure 1, there was no indication of how many readers rated each book, so a data point may be assigned a high or low rating only because of a few readers’ oppinions and the linear regression might be slightly affected by this.
mean_rating_count <- mean(books$ratings_count)
mean_text_reviews_count <- mean(books$text_reviews_count)
median_num_pages <- median(books$num_pages)
books_higher_rate <- books %>%
filter(average_rating > 4.5, ratings_count > mean_rating_count, text_reviews_count > mean_text_reviews_count)
books_higher_rate <- na.omit(books_higher_rate)
books_higher_rate <- books_higher_rate[order(-books_higher_rate$average_rating),]
plot2 <- ggplot(books_higher_rate[1:10,], aes(x=num_pages, y=reorder(title,average_rating), fill = language_code)) +
geom_bar(stat="identity") +
geom_vline(xintercept = median_num_pages, color = "#210649")
plot2 <- plot2 + scale_y_discrete(labels=c('The Wake (The Sandman #10)', 'Season of Mists (The Sandman #4)', 'The Complete Maus', 'Harry Potter and the Goblet of Fire', 'Harry Potter and the Prisoner of Azkaban', 'Harry Potter and the Half-Blood Prince', 'Collected Fictions', 'The Hobbit and The Lord of the Rings', 'Harry Potter Collection (Harry Potter #1-6)', 'The Complete Calvin and Hobbes'))
plot2 <- plot2 + ggtitle("Page Numbers of Top 10 Popular Books") +
xlab("Number of Pages") + ylab("Average Rating by Rank") +
theme(axis.text.y = element_text(size = 9)) +
guides(color = guide_colorbar(title = "Language"))
plot2 <- plot2 + scale_fill_manual(values = c("eng" = "#A988D6")) +
theme(panel.background = element_rect(fill = '#F7F7F7'))
plot2
Figure 2. Plot of the 10 most popular books rank by the average rating on y axis and the number of pages the books’ contain on x axis. A vertical line on the graph represents the median number of pages in all the books in the Books dataset.
As a means of verifying the influence of book page numbers on the average rating, Figure 2 shows the ten most popular books with over 4.5 rating and a rating count and text review count exceeding the mean as “On average, reviews produce an 18% uplift in sales.” (Loiselle, 2022). In spite of the fact that not all ten books had more than the median amount of pages, eight of the ten did. Furthermore, each of the top three books contains over 1,500 pages. Additionally, since English is the most popular language in Australia and the ten most popular books are in English, Dymocks should take this into consideration when selecting products.
books$Rating_Group <- "high"
books <- within(books, Rating_Group[average_rating < 3.5] <- 'median')
books <- within(books, Rating_Group[average_rating < 2] <- 'low')
books$Rating_Group <- factor(books$Rating_Group , levels=c("low", "median", "high"))
plot3 <- ggplot(books, aes(x=num_pages, y = Rating_Group, fill = Rating_Group)) +
geom_boxplot()
plot3 <- plot3 +
theme(panel.background = element_rect(fill = '#F7F7F7')) +
scale_fill_manual(values = c("high" = "#A988D6","median" = "white", "low" = "#F1BA61"))
plot3 <- plot3 +
xlab("Number of Pages") + ylab("Rating Group")
plot3
Figure 3. Boxplot of number of pages books’ have group by high (above 3.5), median (3.5 - 2), and low (below 2) average rating.
The high-rated books, as shown in Figure 3, have more pages on average. Despite some outliers in the graph, high-rated books have a higher median number of pages than median-rated books, and median-rated books also have a higher median number of pages than low-rated books. Supporting the statement that a book with more pages will be more likely to be loved by its customers.
In sum, based on the above evidences, it appears that an increase in the number of pages in a book did affect the rating positively. It is important that Dymocks consider the number of pages in a book when choosing which books to sell since customers with positive shopping and reading experiences are more likely to purchase books or other products from Dymocks.