library(corrplot)
TRUE corrplot 0.95 loaded
#import the required libraries
library(pacman)
library(readxl)
library(knitr)
library(kableExtra)
# library(tidyverse)
getwd()
TRUE [1] "/cloud/project"
setwd("/cloud/project")
list.files()
TRUE [1] "markdown report.Rmd" "markdown-report_files"
TRUE [3] "markdown-report.html" "markdown-report.pdf"
TRUE [5] "markdown-report.Rmd" "project.Rproj"
TRUE [7] "python_Kaizen.py" "R-code-Kaizen.R"
TRUE [9] "SPP-Mozzarella Kaizen.xlsx"
#read the excel file
df = read_excel("SPP-Mozzarella Kaizen.xlsx",sheet ="Transpose")
print(dim(df)) # print the columns and rows
TRUE [1] 34 13
head(df,5)
TRUE # A tibble: 5 × 13
TRUE `Stretch Water Temp` `Curd Salting Level (Kgs/L)` Curd Quantity in the machi…¹
TRUE <dbl> <dbl> <dbl>
TRUE 1 85 0.03 27
TRUE 2 85 0.03 27
TRUE 3 85 0.03 27
TRUE 4 85 0.03 27
TRUE 5 85 0.03 27
TRUE # ℹ abbreviated name: ¹`Curd Quantity in the machine (Kgs)`
TRUE # ℹ 10 more variables: `Fat content` <dbl>, Protein <dbl>, Lactose <dbl>,
TRUE # `Moisture content` <chr>, Yield <dbl>, `Molding staff no.` <dbl>,
TRUE # Browning <dbl>, Stretching <dbl>, Melting <dbl>, Salt <dbl>
#columns
colnames(df)
TRUE [1] "Stretch Water Temp" "Curd Salting Level (Kgs/L)"
TRUE [3] "Curd Quantity in the machine (Kgs)" "Fat content"
TRUE [5] "Protein" "Lactose"
TRUE [7] "Moisture content" "Yield"
TRUE [9] "Molding staff no." "Browning"
TRUE [11] "Stretching" "Melting"
TRUE [13] "Salt"
# Select relevant columns for correlation analysis
correlation_data <- df[, c("Fat content",
"Protein",
"Lactose",
"Moisture content",
"Yield",
"Browning",
"Stretching",
"Melting",
"Salt")]
# Ensure the selected columns are numeric
correlation_data <- as.data.frame(lapply(correlation_data, as.numeric))
# Perform the correlation analysis
correlation_matrix <- cor(correlation_data, use = "complete.obs")
# Display the correlation matrix as a table
# kable(correlation_matrix, caption = "Correlation Matrix")
kable(correlation_matrix, caption = "Correlation Matrix") %>%
kable_styling(full_width = FALSE, position = "center") %>%
add_header_above(c(" " = 1, "Correlation Matrix" = ncol(correlation_matrix))) %>%
column_spec(1, bold = TRUE, border_right = TRUE) %>%
row_spec(0, bold = TRUE) %>%
kable_classic(full_width = F, html_font = "Arial")
| Fat.content | Protein | Lactose | Moisture.content | Yield | Browning | Stretching | Melting | Salt | |
|---|---|---|---|---|---|---|---|---|---|
| Fat.content | 1.0000000 | 0.9999976 | 0.9999977 | 0.9999988 | 0.9999941 | 0.1294462 | 0.0883494 | -0.0284967 | 0.0446232 |
| Protein | 0.9999976 | 1.0000000 | 0.9999999 | 0.9999980 | 0.9999938 | 0.1300714 | 0.0886632 | -0.0290382 | 0.0439371 |
| Lactose | 0.9999977 | 0.9999999 | 1.0000000 | 0.9999981 | 0.9999940 | 0.1301277 | 0.0887624 | -0.0289026 | 0.0439506 |
| Moisture.content | 0.9999988 | 0.9999980 | 0.9999981 | 1.0000000 | 0.9999949 | 0.1296485 | 0.0881584 | -0.0283691 | 0.0447856 |
| Yield | 0.9999941 | 0.9999938 | 0.9999940 | 0.9999949 | 1.0000000 | 0.1300172 | 0.0890561 | -0.0279532 | 0.0446349 |
| Browning | 0.1294462 | 0.1300714 | 0.1301277 | 0.1296485 | 0.1300172 | 1.0000000 | 0.1770463 | 0.1407619 | 0.1628959 |
| Stretching | 0.0883494 | 0.0886632 | 0.0887624 | 0.0881584 | 0.0890561 | 0.1770463 | 1.0000000 | 0.5256011 | 0.1437617 |
| Melting | -0.0284967 | -0.0290382 | -0.0289026 | -0.0283691 | -0.0279532 | 0.1407619 | 0.5256011 | 1.0000000 | 0.2931643 |
| Salt | 0.0446232 | 0.0439371 | 0.0439506 | 0.0447856 | 0.0446349 | 0.1628959 | 0.1437617 | 0.2931643 | 1.0000000 |
# Plot the correlation matrix
corrplot(correlation_matrix, method = "color", type = "upper",
tl.col = "black", tl.srt = 45,
title = "Correlation Matrix", mar = c(0, 0, 2, 0))
“Fat content” has strong positive correlations with “Protein,” “Lactose,” “Moisture content,” and “Yield.”
There are lighter colors indicating weak correlations for certain variable pairs, such as “Stretching” and “Browning,” which show little association.
“Salt” shows some negative correlation with other variables, as indicated by the reddish color, which could suggest an inverse relationship.