This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. This analysis was performed using R and RStudio.
The objective of this project is to explain avocado prices using descriptive analysis. This analysis can help producers, retailers, and grocery stores make decisions about pricing, advertising, and supply-chain strategies.
This dataset contains weekly Hass avocado sales and price information from the Hass Avocado Board. It includes average price, total volume, avocado type, year, and geography.
urlfile <- "https://raw.github.com/utjimmyx/resources/master/avocado_HAA.csv"
data <- read.csv(urlfile, fileEncoding = "UTF-8-BOM")
summary(data)
## date average_price total_volume type
## Length :12628 Min. :0.500 Min. : 253 Length :12628
## N.unique : 154 1st Qu.:1.100 1st Qu.: 15733 N.unique : 2
## N.blank : 0 Median :1.320 Median : 94806 N.blank : 0
## Min.nchar: 8 Mean :1.359 Mean : 325259 Min.nchar: 7
## Max.nchar: 10 3rd Qu.:1.570 3rd Qu.: 430222 Max.nchar: 12
## Max. :2.780 Max. :5660216
## year geography
## Min. :2017 Length :12628
## 1st Qu.:2018 N.unique : 41
## Median :2019 N.blank : 0
## Mean :2019 Min.nchar: 5
## 3rd Qu.:2020 Max.nchar: 20
## Max. :2020
library(plyr)
str(data)
## 'data.frame': 12628 obs. of 6 variables:
## $ date : chr "2017/12/3" "2017/12/3" "2017/12/3" "2017/12/3" ...
## $ average_price: num 1.39 1.44 1.07 1.62 1.43 1.58 1.14 1.77 1.4 1.88 ...
## $ total_volume : int 139970 3577 504933 10609 658939 38754 86646 1829 488588 21338 ...
## $ type : chr "conventional" "organic" "conventional" "organic" ...
## $ year : int 2017 2017 2017 2017 2017 2017 2017 2017 2017 2017 ...
## $ geography : chr "Albany" "Albany" "Atlanta" "Atlanta" ...
hist(
data$average_price,
main = "Histogram of Average Price",
xlab = "Price in USD"
)
library(ggplot2)
ggplot(data, aes(x = average_price, fill = type)) +
geom_histogram(bins = 30, color = "red") +
scale_fill_manual(values = c("blue", "green")) +
ggtitle("Frequency of Average Price: Organic vs. Conventional")
ggplot(data) +
geom_col(
aes(
x = reorder(geography, total_volume),
y = total_volume,
fill = factor(year)
)
) +
xlab("Geography") +
ylab("Total Volume") +
theme(axis.text.x = element_text(angle = 90, size = 7))
The lowest average avocado price recorded was $0.50, and the highest average avocado price recorded was $2.78. Therefore, the price range was $0.50 to $2.78 per avocado.
The Hass Avocado Board’s marketing research can benefit several stakeholders. Growers can use the information to understand demand and plan production. Retailers and grocery stores can use the data to set prices and create promotions. Marketers can use the research to understand consumer trends and develop advertising campaigns. Distributors can also use the information to improve inventory and supply-chain planning.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
##
## arrange, count, desc, mutate, rename, summarise, summarize
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
names(data) <- trimws(names(data))
results <- data %>%
mutate(dollar_sales = average_price * total_volume) %>%
filter(year %in% c(2017, 2018)) %>%
group_by(year, type, geography) %>%
summarise(
total_dollar_sales = sum(dollar_sales, na.rm = TRUE),
.groups = "drop"
) %>%
group_by(year, type) %>%
slice_max(total_dollar_sales, n = 1)
results
## # A tibble: 4 × 4
## # Groups: year, type [4]
## year type geography total_dollar_sales
## <int> <chr> <chr> <dbl>
## 1 2017 conventional Los Angeles 13456647.
## 2 2017 organic New York 720451.
## 3 2018 conventional Los Angeles 153526216.
## 4 2018 organic New York 9391204.
In 2017, New York had the highest organic Hass avocado sales, totaling $720,450.90. Los Angeles had the highest conventional Hass avocado sales, totaling $13,456,646.77. In 2018, New York again had the highest organic Hass avocado sales, totaling $9,391,204.15, while Los Angeles had the highest conventional sales, totaling $153,526,216.27. These cities may have higher avocado sales because of their large populations, high numbers of grocery stores and restaurants, strong consumer demand, and greater purchasing power. New York’s high organic sales may also reflect consumer interest in healthy and organic foods.
ggplot(data, aes(x = type, y = average_price, fill = type)) +
geom_boxplot() +
labs(
title = "Average Avocado Prices by Type",
x = "Avocado Type",
y = "Average Price per Avocado",
fill = "Avocado Type"
) +
theme_minimal()
This figure compares the prices of organic and conventional avocados. Organic avocados generally have higher prices than conventional avocados. This may be caused by higher production costs and consumers’ willingness to pay more for organic products. Retailers can use this information when setting prices and creating promotions.
ggplot(data, aes(x = average_price, y = total_volume, color = type)) +
geom_point(alpha = 0.5) +
geom_smooth(method = "lm", se = FALSE) +
labs(
title = "Relationship Between Price and Sales Volume",
x = "Average Price",
y = "Total Sales Volume",
color = "Avocado Type"
) +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
This figure shows the relationship between avocado prices and sales volume. It helps businesses understand whether sales volume changes when prices increase or decrease. Retailers can use this information to plan discounts, promotions, and pricing strategies.