## # A tibble: 6 × 13
## fixed.acidity volatile.acidity citric.acid residual.sugar chlorides
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 7.4 0.7 0 1.9 0.076
## 2 7.8 0.88 0 2.6 0.098
## 3 7.8 0.76 0.04 2.3 0.092
## 4 11.2 0.28 0.56 1.9 0.075
## 5 7.4 0.7 0 1.9 0.076
## 6 7.4 0.66 0 1.8 0.075
## # ℹ 8 more variables: free.sulfur.dioxide <dbl>, total.sulfur.dioxide <dbl>,
## # density <dbl>, pH <dbl>, sulphates <dbl>, alcohol <dbl>, quality <int>,
## # color <chr>
For my first figure, I am going to create a density plot that plots alcohol distribution for two different type of wine. I will create a two column tibble with these data.
fig_dat1<-dat[,c(11,13)]
fig_dat1
## # A tibble: 6,497 × 2
## alcohol color
## <dbl> <chr>
## 1 9.4 red
## 2 9.8 red
## 3 9.8 red
## 4 9.8 red
## 5 9.4 red
## 6 9.4 red
## 7 9.4 red
## 8 10 red
## 9 9.5 red
## 10 10.5 red
## # ℹ 6,487 more rows
# try to visualize
ggplot(data = fig_dat1, aes(x = alcohol, fill = as.factor(color))) + geom_density(alpha=0.1)+
labs(title="Density plot",
subtitle="# alcohol Distribution")
For my second figure, I am going to create a boxplot for fixed acidity of two different type of wine.
The fixed acidity is calculated from the difference between total acidity and volatile acidity.
fig_dat2<-dat[,c(1,13)]
fig_dat2
## # A tibble: 6,497 × 2
## fixed.acidity color
## <dbl> <chr>
## 1 7.4 red
## 2 7.8 red
## 3 7.8 red
## 4 11.2 red
## 5 7.4 red
## 6 7.4 red
## 7 7.9 red
## 8 7.3 red
## 9 7.8 red
## 10 7.5 red
## # ℹ 6,487 more rows
# try to visualize
ggplot(fig_dat2, aes(x = color, y = fixed.acidity, fill = color)) +
geom_boxplot() +
labs(x = "Wine Type", y = "fixed acidity", title = "Comparison of Alcohol Content in Red and White Wines") +
theme_minimal() +
scale_fill_manual(values = c("red", "white"))
For the third figure, I will display a heatmap of different physicochemical properties of red wine.
A very important factor contributing to wine quality as it affects the acidity of wine. Highly acidic wines with a pH value of less than 3 need other features to balance it out, while the ideal range for wines remains 3.2 to 3.4 with the right amount of acidity. Beyond this value, wines become less acidic and may need additives to increase robustness.
fig_dat3<-tibble(red[,c(-12,-13)])
fig_dat3
## # A tibble: 1,599 × 11
## fixed.acidity volatile.acidity citric.acid residual.sugar chlorides
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 7.4 0.7 0 1.9 0.076
## 2 7.8 0.88 0 2.6 0.098
## 3 7.8 0.76 0.04 2.3 0.092
## 4 11.2 0.28 0.56 1.9 0.075
## 5 7.4 0.7 0 1.9 0.076
## 6 7.4 0.66 0 1.8 0.075
## 7 7.9 0.6 0.06 1.6 0.069
## 8 7.3 0.65 0 1.2 0.065
## 9 7.8 0.58 0.02 2 0.073
## 10 7.5 0.5 0.36 6.1 0.071
## # ℹ 1,589 more rows
## # ℹ 6 more variables: free.sulfur.dioxide <dbl>, total.sulfur.dioxide <dbl>,
## # density <dbl>, pH <dbl>, sulphates <dbl>, alcohol <dbl>
# try to visualize
correlation_matrix <- cor(fig_dat3)
melted_corr_matrix <- melt(correlation_matrix)
ggplot(data = melted_corr_matrix, aes(x=Var1, y=Var2, fill=value)) +
geom_tile() +
theme_minimal() +
labs(title = "Heatmap of Correlation Matrix", x = "", y = "", fill = "Correlation") +
scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0, limit = c(-1,1), space = "Lab", name="Pearson\nCorrelation")
For this figure, I will display a scatter plots to visualize the relationship between different physicochemical properties of red wine. Here I want to see if there’s a correlation between alcohol content and quality.
fig_dat4<-tibble(red[,c(1,9)])
fig_dat4
## # A tibble: 1,599 × 2
## fixed.acidity pH
## <dbl> <dbl>
## 1 7.4 3.51
## 2 7.8 3.2
## 3 7.8 3.26
## 4 11.2 3.16
## 5 7.4 3.51
## 6 7.4 3.51
## 7 7.9 3.3
## 8 7.3 3.39
## 9 7.8 3.36
## 10 7.5 3.35
## # ℹ 1,589 more rows
# try to visualize
ggplot(fig_dat4, aes(x = fixed.acidity, y = pH)) +
geom_point() +
labs(x = "fixed.acidity", y = "pH",
title = "Scatter plot of fixed.acidity vs pH")
For this figure, I am going to create a density plot that plots pH distribution for two different type of wine. I will create a two column tibble with these data.
fig_dat5<-dat[,c(9,13)]
fig_dat5
## # A tibble: 6,497 × 2
## pH color
## <dbl> <chr>
## 1 3.51 red
## 2 3.2 red
## 3 3.26 red
## 4 3.16 red
## 5 3.51 red
## 6 3.51 red
## 7 3.3 red
## 8 3.39 red
## 9 3.36 red
## 10 3.35 red
## # ℹ 6,487 more rows
# try to visualize
ggplot(data = fig_dat5, aes(x = pH, fill = as.factor(color))) + geom_density(alpha=0.1)+
labs(title="Density plot",
subtitle="# pH Distribution")
For this figure, I will display a scatter plots to visualize the relationship between different physicochemical properties of white wine. Here I want to see if there’s a correlation between alcohol content and quality.
# Group by wine type and quality, and count the number of each combination
fig_dat6<-tibble(red[,c(6,9)])
fig_dat6
## # A tibble: 1,599 × 2
## free.sulfur.dioxide pH
## <dbl> <dbl>
## 1 11 3.51
## 2 25 3.2
## 3 15 3.26
## 4 17 3.16
## 5 11 3.51
## 6 13 3.51
## 7 15 3.3
## 8 15 3.39
## 9 9 3.36
## 10 17 3.35
## # ℹ 1,589 more rows
# try to visualize
ggplot(fig_dat6, aes(x = free.sulfur.dioxide, y = pH)) +
geom_point() +
labs(x = "fixed.acidity", y = "pH",
title = "Scatter plot of fixed.acidity vs pH")
For this figure, I am going to compare some correlation of wine properties for Red and White Wines. I will create a six column tibble with these data.
fig_dat7<-dat[,c(1,2,3,9,11,13)]
fig_dat7
## # A tibble: 6,497 × 6
## fixed.acidity volatile.acidity citric.acid pH alcohol color
## <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
## 1 7.4 0.7 0 3.51 9.4 red
## 2 7.8 0.88 0 3.2 9.8 red
## 3 7.8 0.76 0.04 3.26 9.8 red
## 4 11.2 0.28 0.56 3.16 9.8 red
## 5 7.4 0.7 0 3.51 9.4 red
## 6 7.4 0.66 0 3.51 9.4 red
## 7 7.9 0.6 0.06 3.3 9.4 red
## 8 7.3 0.65 0 3.39 10 red
## 9 7.8 0.58 0.02 3.36 9.5 red
## 10 7.5 0.5 0.36 3.35 10.5 red
## # ℹ 6,487 more rows
# try to visualize
ggpairs(fig_dat7, ggplot2::aes(color = as.factor(color))) +
theme_minimal()
For this figure, I am going to create a density plot that plots pH distribution for two different type of wine. I will create a two column tibble with these data.
fig_dat8<-dat[,c(1,13)]
fig_dat8
## # A tibble: 6,497 × 2
## fixed.acidity color
## <dbl> <chr>
## 1 7.4 red
## 2 7.8 red
## 3 7.8 red
## 4 11.2 red
## 5 7.4 red
## 6 7.4 red
## 7 7.9 red
## 8 7.3 red
## 9 7.8 red
## 10 7.5 red
## # ℹ 6,487 more rows
# try to visualize
p <- ggplot(fig_dat8, aes(x = color, y = fixed.acidity, fill = color)) +
geom_boxplot() +
labs(title = "Boxplot of Fixed Acidity by Wine Type", x = "Wine Type", y = "Fixed Acidity") +
theme_minimal()
ggplotly(p)