library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.1 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(rmarkdown)
The dataset was compiled by Brady Brelinski and was gotten from click here
For this analysis, we will create a data frame and gather details of the dataset. the following code chunk helps you do that:
flavours_df <- read.csv("C:/Users/HP PC/OneDrive/Documents/flavors_of_cacao.csv")
head(flavours_df)
## Company...Maker.if.known. Specific.Bean.Origin.or.Bar.Name REF Review.Date
## 1 A. Morin Agua Grande 1876 2016
## 2 A. Morin Kpime 1676 2015
## 3 A. Morin Atsane 1676 2015
## 4 A. Morin Akata 1680 2015
## 5 A. Morin Quilla 1704 2015
## 6 A. Morin Carenero 1315 2014
## Cocoa.Percent Company.Location Rating Bean.Type Broad.Bean.Origin
## 1 63% France 3.75 Sao Tome
## 2 70% France 2.75 Togo
## 3 70% France 3.00 Togo
## 4 70% France 3.50 Togo
## 5 70% France 3.50 Peru
## 6 70% France 2.75 Criollo Venezuela
str(flavours_df)
## 'data.frame': 1795 obs. of 9 variables:
## $ Company...Maker.if.known. : chr "A. Morin" "A. Morin" "A. Morin" "A. Morin" ...
## $ Specific.Bean.Origin.or.Bar.Name: chr "Agua Grande" "Kpime" "Atsane" "Akata" ...
## $ REF : int 1876 1676 1676 1680 1704 1315 1315 1315 1319 1319 ...
## $ Review.Date : int 2016 2015 2015 2015 2015 2014 2014 2014 2014 2014 ...
## $ Cocoa.Percent : chr "63%" "70%" "70%" "70%" ...
## $ Company.Location : chr "France" "France" "France" "France" ...
## $ Rating : num 3.75 2.75 3 3.5 3.5 2.75 3.5 3.5 3.75 4 ...
## $ Bean.Type : chr " " " " " " " " ...
## $ Broad.Bean.Origin : chr "Sao Tome" "Togo" "Togo" "Togo" ...
colnames(flavours_df)
## [1] "Company...Maker.if.known." "Specific.Bean.Origin.or.Bar.Name"
## [3] "REF" "Review.Date"
## [5] "Cocoa.Percent" "Company.Location"
## [7] "Rating" "Bean.Type"
## [9] "Broad.Bean.Origin"
first, i narrowed down the data to interested columns by:
trimmed_flavors_df <- flavours_df %>%
select(Rating, Cocoa.Percent, Company.Location)
In other to know the best chocolates, i have to find the mean rating to know my bench mark for the best chocolates
trimmed_flavors_df%>%
summarise(mean_rating = mean(Rating))
## mean_rating
## 1 3.185933
I also have to know the maximum rating, hence:
trimmed_flavors_df%>%
summarise(max_rating = max(Rating))
## max_rating
## 1 5
Now that i know my prefered rating, i then have to filter the data with it to get the best chocolate from the data (using 80% as my bench mark for the “Cocoa.Percent” column )
best_trimmed_flavors_df <- trimmed_flavors_df %>%
filter(Cocoa.Percent>=80, Rating>=3.75)
Now that my data is cleaned, i need to view it so:
View(best_trimmed_flavors_df)
With the help of a bar chart i am able to know the countries with the best chocolates:
ggplot(data=best_trimmed_flavors_df)+geom_bar(mapping = aes(x=Company.Location, fill = Rating)) + labs(title = "Countries With The Best Chocolates")
Hence, Canada and France are the countries with the best chocolates.
while with the help of a scatter plot i able to know the relationship between Cocoa.Percent and Rating:
ggplot(data = trimmed_flavors_df)+geom_point(mapping = aes(x = Cocoa.Percent, y = Rating, color=Rating)) + labs(title = "Best Chocolates")