sales_by_publisher <- book_sales |>
group_by(Publisher) |>
summarize(
total_units_sold = sum(`units sold`),
total_gross_sales = sum(`gross sales`),
total_revenue = sum(`publisher revenue`)
)
sales_by_publisher
## # A tibble: 7 × 4
## Publisher total_units_sold total_gross_sales total_revenue
## <chr> <dbl> <dbl> <dbl>
## 1 Amazon Digital Services, In… 6074136 729809. 148244.
## 2 Hachette Book Group 543821 229791. 137874.
## 3 HarperCollins Publishers 649294 222408. 133445.
## 4 Macmillan 334929 53927. 32356.
## 5 Penguin Group (USA) LLC 934303 356362. 213817.
## 6 Random House LLC 1315958 315975. 189585.
## 7 Simon and Schuster Digital S… 501928 78314. 46988.
This group showcases a summary of total units sold, total gross sales, and total publisher revenue for each publisher in the data set. From this, we can see that Amazon Digital Services, Inc. tops the chart for each category summarized.
To continue with this, I wanted to see which publishers had the lowest probability of having a revenue over $150,000.
#finding publisher with lowest probability of having a revenue of over $150,000
#defining criteria
revenue_150k <- 150000
#calculate the probability of a publisher's total revenue being over $150,000
sales_by_publisher <- sales_by_publisher |>
mutate(probability_over_criteria = total_revenue > revenue_150k)
#identify the publisher(s) with the lowest probability
lowest_prob_publisher <- sales_by_publisher |>
filter(probability_over_criteria == min(probability_over_criteria)) |>
arrange(probability_over_criteria) |>
head(1)
#mutate a column that adds a tag if the condition is met
book_sales <- book_sales |>
mutate(Lowest_Prob_Tag = ifelse(Publisher %in% lowest_prob_publisher$Publisher,
"Lowest_Prob_Group_Publisher", NA))
head(book_sales)
## # A tibble: 6 × 16
## index `Publishing Year` `Book Name` Author language_code Author_Rating
## <dbl> <dbl> <chr> <chr> <chr> <chr>
## 1 0 1975 Beowulf Unkno… en-US Novice
## 2 1 1987 Batman: Year One Frank… eng Intermediate
## 3 2 2015 Go Set a Watchman Harpe… eng Novice
## 4 3 2008 When You Are Engul… David… en-US Intermediate
## 5 4 2011 Daughter of Smoke … Laini… eng Intermediate
## 6 5 2015 Red Queen Victo… eng Intermediate
## # ℹ 10 more variables: Book_average_rating <dbl>, Book_ratings_count <dbl>,
## # genre <chr>, `gross sales` <dbl>, `publisher revenue` <dbl>,
## # `sale price` <dbl>, `sales rank` <dbl>, Publisher <chr>,
## # `units sold` <dbl>, Lowest_Prob_Tag <chr>
Very surprisingly, Amazon came back as the publisher with the lowest probability of having a revenue of over $150,000. I have a very strong suspicion that something is wrong with my code here, but I will continue to analyze other groups nonetheless.
Similar to the above group-by example, I wanted to view the units sold, gross sales, and publisher revenue but grouped by year rather than publisher.
book_sales_by_year <- book_sales |>
group_by(`Publishing Year`) |>
summarize(
total_units_sold = sum(`units sold`),
total_gross_sales = sum(`gross sales`),
total_revenue = sum(`publisher revenue`),
average_rating = mean(Book_average_rating)
) |>
arrange(desc(total_gross_sales))
book_sales_by_year
## # A tibble: 151 × 5
## `Publishing Year` total_units_sold total_gross_sales total_revenue
## <dbl> <dbl> <dbl> <dbl>
## 1 2011 635477 135434. 71987.
## 2 2008 150000 108108. 57443.
## 3 2012 769084 97114. 51444.
## 4 2015 231140 87869. 38019.
## 5 2006 181223 85493. 36005.
## 6 2009 468282 65535. 32294.
## 7 2007 427143 63867. 31798.
## 8 2003 521747 60511. 26504.
## 9 1995 134647 60349. 23508.
## 10 2010 489571 54109. 18217.
## # ℹ 141 more rows
## # ℹ 1 more variable: average_rating <dbl>
For the sake of viewing, I arranged this summary descending by the total gross sales, which gave us an easy view of 2011, 2008, 2012, 2015, and 2006 being the top years for sales.
#find probability of publishing year having high book ratings
#define a high rating of 4 since the ratings are out of 5
high_rating <- 4.0
#calculate the probability of a publishing year having high ratings
year_high_ratings_probability <- book_sales_by_year %>%
summarize(probability_high_ratings = sum(average_rating > high_rating) / n())
print(year_high_ratings_probability$probability_high_ratings)
## [1] 0.4900662
According to the code above, there is a 49% chance of a year having an average rating greater than 4. This seems a bit unlikely, so I once again do not think this code is correct.
This group goes a slightly different direction by focusing a bit more on not only sales, but also book ratings grouped by author.
avg_book_rating_by_auth <- book_sales |>
group_by(Author) |>
summarize(
total_units_sold = sum(`units sold`),
total_gross_sales = sum(`gross sales`),
total_revenue = sum(`publisher revenue`),
total_ratings_count = sum(Book_ratings_count),
avg_book_rating = mean(Book_average_rating)
) |>
arrange(desc(total_gross_sales))
avg_book_rating_by_auth
## # A tibble: 735 × 6
## Author total_units_sold total_gross_sales total_revenue total_ratings_count
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Harper … 5500 47795 28677 138669
## 2 Stephen… 278322 43323. 16745. 2838201
## 3 David S… 15193 42323. 25037. 315105
## 4 Charlai… 47249 39453. 22246. 1452827
## 5 Laini T… 8990 38278. 22967. 284029
## 6 Unknown… 7000 34160 20496 155903
## 7 Sarah D… 42832 31035. 7843. 687798
## 8 Colleen… 123522 30882. 17878. 795498
## 9 C.S. Le… 8381 28973. 17384. 423403
## 10 Brandon… 53460 28877. 15663. 757148
## # ℹ 725 more rows
## # ℹ 1 more variable: avg_book_rating <dbl>
I continued with the focus on gross sales and arranged the summary descending by the total gross sales. I found this summary to be very interesting, as the author with the highest gross sales, Harper Lee, did not have the nearly the most units sold or the highest book ratings.
Similarly to the previous group-by example, I wanted to look at the probability of an author having a high average book rating.
#find probability of author having high book ratings
#define a high rating of 4 since the ratings are out of 5
high_rating <- 4.0
#calculate the probability of an author having high average ratings
author_high_ratings_probability <- avg_book_rating_by_auth |>
summarize(probability_high_ratings = mean(avg_book_rating > high_rating))
print(author_high_ratings_probability$probability_high_ratings)
## [1] 0.4938776
This indicates that there is a 49.39% chance that an author will have an average book rating of over 4. In order to visualize this, I opted to use a histagram to show the distribution of average book ratings.
#visualization
ggplot(avg_book_rating_by_auth, aes(x = avg_book_rating)) +
geom_histogram(binwidth = 0.1, fill = "aquamarine3", color = "black", alpha = 0.7) +
labs(title = "Distribution of Average Ratings Among Authors",
x = "Average Rating", y = "Number of Authors") +
theme_minimal()
Based on the histogram, it does show a large portion of books over the 4.0 threshold, which indicates that my calculated probability could be accurate.
From the previous data dive, I knew that the children genre had the fewest number of books. Knowing this, I wanted to see if there were any publishers that did not have any children books.
#create new table
childrens_books_count <- table(book_sales$Publisher, book_sales$genre == 'children')
#convert to data frame and add column names
childrens_books_count_df <- as.data.frame.matrix(childrens_books_count)
colnames(childrens_books_count_df) <- c("Total_Books", "Childrens_Books")
#replace NA with 0 to show publishers with no childrens books
childrens_books_count_df[is.na(childrens_books_count_df)] <- 0
print(childrens_books_count)
##
## FALSE TRUE
## Amazon Digital Services, Inc. 589 11
## Hachette Book Group 66 0
## HarperCollins Publishers 78 1
## Macmillan 40 1
## Penguin Group (USA) LLC 108 0
## Random House LLC 118 2
## Simon and Schuster Digital Sales Inc 56 0
The table’s “True” column indicates the number of children books by each publisher. We can see that Hachette Book Group, Penguin Group (USA) LLC, and Simon and Schuster Digital Sales Inc do not have any books for children published in the time frame of the dataset.
My initial guess as to why there is no combination of these publishers and the children book genre is because these publishers simply do not focus on that genre and perhaps prefer to only publish fiction or nonfiction books for adults.
The most common combination of publisher and children book genre is Amazon Digital Services, Inc., which I do not find very surprising since it has been demonstrated previously that this publisher has the most amount of published books be a good margin. From there, Random House LLC is the second most common combination of publisher and children book genre.