# 1. What are the key factors influencing wine quality?
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
red_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityReds.csv")
white_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityWhites.csv")
ggplot(red_wine_data, aes(x = alcohol, y = quality)) +
geom_point() +
geom_smooth(method = "lm") +
labs(x = "Alcohol Content", y = "Quality") +
ggtitle("Red Wine: Alcohol Content vs. Wine Quality")
## `geom_smooth()` using formula = 'y ~ x'

ggplot(white_wine_data, aes(x = alcohol, y = quality)) +
geom_point() +
geom_smooth(method = "lm") +
labs(x = "Alcohol Content", y = "Quality") +
ggtitle("White Wine: Alcohol Content vs. Wine Quality")
## `geom_smooth()` using formula = 'y ~ x'

ggplot(red_wine_data, aes(x = quality)) +
geom_bar(fill = "blue") +
labs(x = "Quality", y = "Frequency") +
ggtitle("Red Wine: Distribution of Wine Quality Ratings")

ggplot(white_wine_data, aes(x = quality)) +
geom_bar(fill = "blue") +
labs(x = "Quality", y = "Frequency") +
ggtitle("White Wine: Distribution of Wine Quality Ratings")

# 2. What is the distribution of fixed acidity in red and white wines?
library(ggplot2)
library(gridExtra)
## Warning: package 'gridExtra' was built under R version 4.3.3
red_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityReds.csv")
white_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityWhites.csv")
red_histogram <- ggplot(red_wine_data, aes(x = fixed.acidity)) +
geom_histogram(fill = "red", color = "black", bins = 20) +
labs(title = "Distribution of Fixed Acidity in Red Wines",
x = "Fixed Acidity",
y = "Frequency")
white_histogram <- ggplot(white_wine_data, aes(x = fixed.acidity)) +
geom_histogram(fill = "blue", color = "black", bins = 20) +
labs(title = "Distribution of Fixed Acidity in White Wines",
x = "Fixed Acidity",
y = "Frequency")
grid.arrange(red_histogram, white_histogram, nrow = 1)

# 3. How does volatile acidity vary across different quality ratings of red wines?
library(ggplot2)
red_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityReds.csv")
ggplot(red_wine_data, aes(x = factor(quality), y = volatile.acidity)) +
geom_boxplot(fill = "blue") +
labs(title = "Volatile Acidity Across Di erent Quality Ratings of Red Wines",
x = "Quality Rating",
y = "Volatile Acidity")

# 4. Is there a correlation between citric acid content and pH in white wines?
library(ggplot2)
white_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityWhites.csv")
ggplot(white_wine_data, aes(x = citric.acid, y = pH)) +
geom_point() + labs(title = "Citric Acid Content vs. pH in White Wines",
x = "Citric Acid Content",
y = "pH") +
geom_smooth(method = "lm", se = FALSE, color = "blue")
## `geom_smooth()` using formula = 'y ~ x'

correlation <- cor(white_wine_data$citric.acid, white_wine_data$pH)
print(paste("Correlation coe icient:", correlation))
## [1] "Correlation coe icient: -0.163748211400624"
#5 What is the average residual sugar content in high-quality red wines?
library(dplyr)
##
## Attaching package: 'dplyr'
## The following object is masked from 'package:gridExtra':
##
## combine
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
red_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityReds.csv")
high_quality_red_wines <- filter(red_wine_data, quality >= 7)
average_residual_sugar <- mean(high_quality_red_wines$residual.sugar)
print(paste("Average residual sugar content in high-quality red wines:", round(average_residual_sugar, 2)))
## [1] "Average residual sugar content in high-quality red wines: 2.71"
# 6 How do chlorides levels di er between red and white wines?
library(ggplot2)
red_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityReds.csv")
white_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityWhites.csv")
red_wine_data$type <- "Red Wine"
white_wine_data$type <- "White Wine"
combined_data <- rbind(red_wine_data, white_wine_data)
ggplot(combined_data, aes(x = type, y = chlorides, fill = type)) +
geom_boxplot() +
labs(title = "Chloride Levels in Red and White Wines",
x = NULL,
y = "Chloride Levels",
fill = "Wine Type") +
scale_fill_manual(values = c("red", "blue")) +
theme_minimal()

# 7 Is there a relationship between free sulfur dioxide and total sulfur dioxide in white wines?
library(ggplot2)
white_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityWhites.csv")
ggplot(white_wine_data, aes(x = free.sulfur.dioxide, y = total.sulfur.dioxide)) +
geom_point() +
labs(title = "Relationship Between Free Sulfur Dioxide and Total Sulfur Dioxide in White Wines",
x = "Free Sulfur Dioxide",
y = "Total Sulfur Dioxide") +
geom_smooth(method = "lm", se = FALSE, color = "blue")
## `geom_smooth()` using formula = 'y ~ x'

correlation <- cor(white_wine_data$free.sulfur.dioxide, white_wine_data$total.sulfur.dioxide)
print(paste("Correlation coefficient:", correlation))
## [1] "Correlation coefficient: 0.615500965009836"
# 8 What is the range of density values observed in red wines?
red_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityReds.csv")
min_density <- min(red_wine_data$density)
max_density <- max(red_wine_data$density)
print(paste("Range of density values observed in red wines:", min_density, "-", max_density))
## [1] "Range of density values observed in red wines: 0.99007 - 1.00369"
# 9 How does pH change with increasing alcohol content in red wines?
library(ggplot2)
red_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityReds.csv")
ggplot(red_wine_data, aes(x = alcohol, y = pH)) +
geom_point() +
labs(title = "pH vs. Alcohol Content in Red Wines",
x = "Alcohol Content",
y = "pH") +
geom_smooth(method = "lm", se = FALSE, color = "blue")
## `geom_smooth()` using formula = 'y ~ x'

# 10 Are sulphates levels higher in white wines compared to red wines?
library(ggplot2)
red_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityReds.csv")
white_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityWhites.csv")
ggplot() +
geom_boxplot(data = red_wine_data, aes(x = "Red Wine", y = sulphates), fill = "red", alpha = 0.5) +
geom_boxplot(data = white_wine_data, aes(x = "White Wine", y = sulphates), fill = "blue", alpha = 0.5) + labs(title = "Sulfates Levels in Red and White Wines",
x = NULL,
y = "Sulfates Levels")

# 11 What is the median alcohol content in red wines of different quality ratings?
library(dplyr)
red_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityReds.csv")
median_alcohol <- red_wine_data %>%
group_by(quality) %>%
summarize(median_alcohol = median(alcohol))
print(median_alcohol)
## # A tibble: 6 × 2
## quality median_alcohol
## <int> <dbl>
## 1 3 9.93
## 2 4 10
## 3 5 9.7
## 4 6 10.5
## 5 7 11.5
## 6 8 12.2
# 12 How does fixed acidity aƯect the perceived quality of red wines?
library(ggplot2)
red_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityReds.csv")
ggplot(red_wine_data, aes(x = fixed.acidity, y = quality)) +
geom_point() +
labs(title = "Fixed Acidity vs. Quality Ratings in Red Wines",
x = "Fixed Acidity",
y = "Quality")

# 13 Can volatile acidity be used as a predictor of wine spoilage?
library(ggplot2)
wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityReds.csv")
ggplot(wine_data, aes(x = volatile.acidity, y = quality)) +
geom_point() +
labs(title = "Volatile Acidity vs. Quality Ratings in Red Wines",
x = "Volatile Acidity",
y = "Quality") +
geom_smooth(method = "lm", se = FALSE, color = "blue")
## `geom_smooth()` using formula = 'y ~ x'

# 14 What is the impact of citric acid on the acidity level of white wines?
library(ggplot2)
white_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityWhites.csv")
ggplot(white_wine_data, aes(x = citric.acid, y = pH)) +
geom_point() +
labs(title = "Citric Acid vs. pH Levels in White Wines",
x = "Citric Acid",
y = "pH")

# 15 Are there any trends between chlorides concentration and wine quality?
red_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityReds.csv")
ggplot(red_wine_data, aes(x = chlorides, y = quality)) +
geom_point() +
labs(title = "Chlorides vs. Quality Ratings in Red Wines",
x = "Chlorides",
y = "Quality")

ggplot(red_wine_data, aes(x = as.factor(quality), y = chlorides)) +
geom_boxplot() +
labs(title = "Distribution of Chlorides Concentration by Quality Ratings in Red Wines",
x = "Quality",
y = "Chlorides Concentration")

# 16 Is there a significant diƯerence in free sulfur dioxide levels between red and white wines?
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.1
## ✔ readr 2.1.5
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::combine() masks gridExtra::combine()
## ✖ 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
red_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityReds.csv")
white_wine_data <- read.csv("C:/Users/risha/Downloads/wineQualityWhites.csv")
t_test_result <- t.test(red_wine_data$free.sulfur.dioxide, white_wine_data$free.sulfur.dioxide)
print(t_test_result)
##
## Welch Two Sample t-test
##
## data: red_wine_data$free.sulfur.dioxide and white_wine_data$free.sulfur.dioxide
## t = -54.428, df = 4461.9, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -20.13315 -18.73318
## sample estimates:
## mean of x mean of y
## 15.87492 35.30808