# Convert Class to a factor
library(datasetsICR)
data(wine)LM 3.1
Loading in Dataset
Looking at the first and last 10 rows and structure of the dataset
# Looking at the first and last 10 rows and structure of the dataset
head(wine, 10) # lower number for malic acid Class Alcohol Malic acid Ash Alcalinity of ash Magnesium Total phenols
1 1 14.23 1.71 2.43 15.6 127 2.80
2 1 13.20 1.78 2.14 11.2 100 2.65
3 1 13.16 2.36 2.67 18.6 101 2.80
4 1 14.37 1.95 2.50 16.8 113 3.85
5 1 13.24 2.59 2.87 21.0 118 2.80
6 1 14.20 1.76 2.45 15.2 112 3.27
7 1 14.39 1.87 2.45 14.6 96 2.50
8 1 14.06 2.15 2.61 17.6 121 2.60
9 1 14.83 1.64 2.17 14.0 97 2.80
10 1 13.86 1.35 2.27 16.0 98 2.98
Flavanoids Nonflavanoid phenols Proanthocyanins Color intensity Hue
1 3.06 0.28 2.29 5.64 1.04
2 2.76 0.26 1.28 4.38 1.05
3 3.24 0.30 2.81 5.68 1.03
4 3.49 0.24 2.18 7.80 0.86
5 2.69 0.39 1.82 4.32 1.04
6 3.39 0.34 1.97 6.75 1.05
7 2.52 0.30 1.98 5.25 1.02
8 2.51 0.31 1.25 5.05 1.06
9 2.98 0.29 1.98 5.20 1.08
10 3.15 0.22 1.85 7.22 1.01
OD280/OD315 of diluted wines Proline
1 3.92 1065
2 3.40 1050
3 3.17 1185
4 3.45 1480
5 2.93 735
6 2.85 1450
7 3.58 1290
8 3.58 1295
9 2.85 1045
10 3.55 1045
tail(wine, 10) # lower number for hue Class Alcohol Malic acid Ash Alcalinity of ash Magnesium Total phenols
169 3 13.58 2.58 2.69 24.5 105 1.55
170 3 13.40 4.60 2.86 25.0 112 1.98
171 3 12.20 3.03 2.32 19.0 96 1.25
172 3 12.77 2.39 2.28 19.5 86 1.39
173 3 14.16 2.51 2.48 20.0 91 1.68
174 3 13.71 5.65 2.45 20.5 95 1.68
175 3 13.40 3.91 2.48 23.0 102 1.80
176 3 13.27 4.28 2.26 20.0 120 1.59
177 3 13.17 2.59 2.37 20.0 120 1.65
178 3 14.13 4.10 2.74 24.5 96 2.05
Flavanoids Nonflavanoid phenols Proanthocyanins Color intensity Hue
169 0.84 0.39 1.54 8.660000 0.74
170 0.96 0.27 1.11 8.500000 0.67
171 0.49 0.40 0.73 5.500000 0.66
172 0.51 0.48 0.64 9.899999 0.57
173 0.70 0.44 1.24 9.700000 0.62
174 0.61 0.52 1.06 7.700000 0.64
175 0.75 0.43 1.41 7.300000 0.70
176 0.69 0.43 1.35 10.200000 0.59
177 0.68 0.53 1.46 9.300000 0.60
178 0.76 0.56 1.35 9.200000 0.61
OD280/OD315 of diluted wines Proline
169 1.80 750
170 1.92 630
171 1.83 510
172 1.63 470
173 1.71 660
174 1.74 740
175 1.56 750
176 1.56 835
177 1.62 840
178 1.60 560
str(wine)'data.frame': 178 obs. of 14 variables:
$ Class : int 1 1 1 1 1 1 1 1 1 1 ...
$ Alcohol : num 14.2 13.2 13.2 14.4 13.2 ...
$ Malic acid : num 1.71 1.78 2.36 1.95 2.59 1.76 1.87 2.15 1.64 1.35 ...
$ Ash : num 2.43 2.14 2.67 2.5 2.87 2.45 2.45 2.61 2.17 2.27 ...
$ Alcalinity of ash : num 15.6 11.2 18.6 16.8 21 15.2 14.6 17.6 14 16 ...
$ Magnesium : int 127 100 101 113 118 112 96 121 97 98 ...
$ Total phenols : num 2.8 2.65 2.8 3.85 2.8 3.27 2.5 2.6 2.8 2.98 ...
$ Flavanoids : num 3.06 2.76 3.24 3.49 2.69 3.39 2.52 2.51 2.98 3.15 ...
$ Nonflavanoid phenols : num 0.28 0.26 0.3 0.24 0.39 0.34 0.3 0.31 0.29 0.22 ...
$ Proanthocyanins : num 2.29 1.28 2.81 2.18 1.82 1.97 1.98 1.25 1.98 1.85 ...
$ Color intensity : num 5.64 4.38 5.68 7.8 4.32 6.75 5.25 5.05 5.2 7.22 ...
$ Hue : num 1.04 1.05 1.03 0.86 1.04 1.05 1.02 1.06 1.08 1.01 ...
$ OD280/OD315 of diluted wines: num 3.92 3.4 3.17 3.45 2.93 2.85 3.58 3.58 2.85 3.55 ...
$ Proline : int 1065 1050 1185 1480 735 1450 1290 1295 1045 1045 ...
Summary statistics
# Summary statistics
summary(wine) Class Alcohol Malic acid Ash
Min. :1.000 Min. :11.03 Min. :0.740 Min. :1.360
1st Qu.:1.000 1st Qu.:12.36 1st Qu.:1.603 1st Qu.:2.210
Median :2.000 Median :13.05 Median :1.865 Median :2.360
Mean :1.938 Mean :13.00 Mean :2.336 Mean :2.367
3rd Qu.:3.000 3rd Qu.:13.68 3rd Qu.:3.083 3rd Qu.:2.558
Max. :3.000 Max. :14.83 Max. :5.800 Max. :3.230
Alcalinity of ash Magnesium Total phenols Flavanoids
Min. :10.60 Min. : 70.00 Min. :0.980 Min. :0.340
1st Qu.:17.20 1st Qu.: 88.00 1st Qu.:1.742 1st Qu.:1.205
Median :19.50 Median : 98.00 Median :2.355 Median :2.135
Mean :19.49 Mean : 99.74 Mean :2.295 Mean :2.029
3rd Qu.:21.50 3rd Qu.:107.00 3rd Qu.:2.800 3rd Qu.:2.875
Max. :30.00 Max. :162.00 Max. :3.880 Max. :5.080
Nonflavanoid phenols Proanthocyanins Color intensity Hue
Min. :0.1300 Min. :0.410 Min. : 1.280 Min. :0.4800
1st Qu.:0.2700 1st Qu.:1.250 1st Qu.: 3.220 1st Qu.:0.7825
Median :0.3400 Median :1.555 Median : 4.690 Median :0.9650
Mean :0.3619 Mean :1.591 Mean : 5.058 Mean :0.9574
3rd Qu.:0.4375 3rd Qu.:1.950 3rd Qu.: 6.200 3rd Qu.:1.1200
Max. :0.6600 Max. :3.580 Max. :13.000 Max. :1.7100
OD280/OD315 of diluted wines Proline
Min. :1.270 Min. : 278.0
1st Qu.:1.938 1st Qu.: 500.5
Median :2.780 Median : 673.5
Mean :2.612 Mean : 746.9
3rd Qu.:3.170 3rd Qu.: 985.0
Max. :4.000 Max. :1680.0
summary(wine$Hue) Min. 1st Qu. Median Mean 3rd Qu. Max.
0.4800 0.7825 0.9650 0.9574 1.1200 1.7100
summary(wine$`Malic acid`) Min. 1st Qu. Median Mean 3rd Qu. Max.
0.740 1.603 1.865 2.336 3.083 5.800
Creating a Table
# creating a Table
wine$Class <- factor(wine$Class)
table(wine$Class)
1 2 3
59 71 48
Creating a Scatterplot
library(ggplot2)
plot <- ggplot(wine, aes(x = Hue, y = `Malic acid`, color = Class)) +
geom_point(shape = 20, size=5) +
scale_x_log10() +
scale_y_log10() +
labs(
x = "Hue",
y = "Malic acid",
title = "Scatter Plot of Hue vs. Malic Acid by Wine Class",
subtitle = "Class 3 has the lowest Hue value but highest Malic Acid count",
caption = "Data Source: datasetsICR, wine"
) +
theme_minimal() +
theme(legend.position = "right")
plotggsave(filename = "LM3picture.png", plot = plot)Saving 7 x 5 in image
Interpretation
In this dataset, there are three wine cultivators. I am specifically analyzing the hue and malic acid components of the wine. Hue helps describe pH of the wine, and the pH of the wine will describe the color. Malic acid provides a good insight to how acidic the wine will taste. Hue and malic acid are linked because the lower the pH, most likely the higher the malic acid.
Class 1 has a hue value gathered around 1 and malic acid counts gathered around 2. Class 1 will not be the most acidic nor the strongest in color. Class 2 is more scattered across the graph. However, it does generally contain the wines with the highest hue value, and values with the middle or lowest malic acid value. Class 2 is lower in hue, which means it has a lower pH level. This describes the lower malic acid values. Lastly, Class 3 has the lowest hue values, making it the class with the highest pH levels. Class 3 has has the highest malic acid values.