library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.0     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.1     ✔ tibble    3.1.8
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
library(patchwork)
## Leaves Category
leaves_data <- tibble(
  Disease = c("Anthracnose", "Healthy", "Powdery Mildew", "Sooty Mould", "Scab"),
  NumberofLeaves = c(521, 500, 320, 212, 0)
  )

leavesPartion <- tibble(
  Identification = c("Train", "Validation"),
  Result = c(1236, 308)
)

allData <- ggplot(leaves_data) +
  aes(x = fct_reorder(Disease,NumberofLeaves,.desc = T), y = NumberofLeaves) +
  geom_col(fill = "green", width = 0.6) +
  theme_minimal() +
  geom_text(aes(label = paste(format(NumberofLeaves, nsmall = 0))), nudge_y = 20) +
  labs(
    title = "Amount of Data",
    y = "",
    x = ""
  ) +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(size = 12, face = "bold", angle = 50, hjust = .8)
  ) 

Partition <- ggplot(leavesPartion) +
  aes(x =  Identification, y = Result, fill = Identification) +
  geom_col(width = 0.4, show.legend = F) +
  theme_minimal() +
  scale_fill_manual(values = c(
    Train = "#13D2D2", Validation = "#13D277"
  ))+
  geom_text(aes(label = paste(format(Result, nsmall = 0))), nudge_y = 100) +
  labs(
    title = "Partition of Data with  80/20 split",
    y = "",
    x = ""
  ) +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(size = 10, face = "bold")

  ) 
(allData | Partition) + 
  plot_annotation(title = "Leaf Category", theme = theme(
    plot.title = element_text(hjust = 0.5, size = 20L, face = "bold")
  ))

## Fruit Category

FruitData <- tibble(
  Disease = c("Anthracnose", "Scab","Sooty Mould", "Stem-End Rot"),
  NumberofFuits = c(206, 216, 222, 219)
  )

FruitPartion <- tibble(
  Identification = c("Train", "Validation"),
  Result = c(594, 146)
)

 AllFruitData <- ggplot(FruitData) +
  aes(x = fct_reorder(Disease,NumberofFuits,.desc = T), y = NumberofFuits) +
  geom_col(fill = "yellow", width = 0.6) +
  theme_minimal() +
  geom_text(aes(label = paste(format(NumberofFuits, nsmall = 0))), nudge_y = 20) +
  labs(
    title = "Amount of Data",
    y = "",
    x = ""
  ) +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(size = 12, face = "bold", angle = 50, hjust = .8)
  )


PartitionFruit <- ggplot(FruitPartion) +
  aes(x =  Identification, y = Result, fill = Identification) +
  geom_col(width = 0.4, show.legend = F) +
  theme_minimal() +
  scale_fill_manual(values = c(
    Train = "#13D2D2", Validation = "#13D277"
  ))+
  geom_text(aes(label = paste(format(Result, nsmall = 0))), nudge_y = 50) +
  labs(
    title = "Partition of Data with  80/20 split",
    y = "",
    x = ""
  ) +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(size = 10, face = "bold")

  ) 
(AllFruitData | PartitionFruit) + 
  plot_annotation(title = "Fruit Category", theme = theme(
    plot.title = element_text(hjust = 0.5, size = 20L, face = "bold")
  ))

FruitData
## # A tibble: 4 × 2
##   Disease      NumberofFuits
##   <chr>                <dbl>
## 1 Anthracnose            206
## 2 Scab                   216
## 3 Sooty Mould            222
## 4 Stem-End Rot           219
## Pest Category

PestData <- tibble(
  Disease = c("Capsid Bug", "Mango Fruit Fly","Mango Seed Borer", "Mango Stem Borer", "Scale Insect"),
  NumberofPests = c(229, 207, 203, 204,216)
  )

PestsPartion <- tibble(
  Identification = c("Train", "Validation"),
  Result = c(842, 207)
)

 AllPestData <- ggplot(PestData) +
  aes(x = fct_reorder(Disease,NumberofPests,.desc = T), y = NumberofPests) +
  geom_col(fill = "purple", width = 0.6) +
  theme_minimal() +
  geom_text(aes(label = paste(format(NumberofPests, nsmall = 0))), nudge_y = 20) +
  labs(
    title = "Amount of Data",
    y = "",
    x = ""
  ) +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(size = 10, face = "bold", angle = 50, hjust = .8)
  )


PartitionPest <- ggplot(PestsPartion) +
  aes(x =  Identification, y = Result, fill = Identification) +
  geom_col(width = 0.4, show.legend = F) +
  theme_minimal() +
  scale_fill_manual(values = c(
    Train = "#13D2D2", Validation = "#13D277"
  ))+
  geom_text(aes(label = paste(format(Result, nsmall = 0))), nudge_y = 50) +
  labs(
    title = "Partition of Data with  80/20 split",
    y = "",
    x = ""
  ) +
  theme(
    plot.title = element_text(hjust = 0.5),
    axis.text.x = element_text(size = 10, face = "bold")

  ) 
(AllPestData | PartitionFruit) + 
  plot_annotation(title = "Pest Category", theme = theme(
    plot.title = element_text(hjust = 0.5, size = 20L, face = "bold")
  ))

PestData
## # A tibble: 5 × 2
##   Disease          NumberofPests
##   <chr>                    <dbl>
## 1 Capsid Bug                 229
## 2 Mango Fruit Fly            207
## 3 Mango Seed Borer           203
## 4 Mango Stem Borer           204
## 5 Scale Insect               216
## Accuracy and Loss

epochsResultAccuracy <- tibble(
  epochs = c(1:10),
  train = c(0.6828479170799255, 0.8616504669189453, 0.9822006225585938, 0.995954692363739, 0.995954692363739, 0.9983818531036377, 1.0, 1.0, 1.0, 1.0),
  validation = c(0.8344155550003052, 0.9155844449996948, 0.9870129823684692, 0.9870129823684692, 0.9805194735527039, 0.9870129823684692, 0.9870129823684692, 0.9902597665786743, 0.9902597665786743, 0.9902597665786743)
)
epochsResultAccuracy <- epochsResultAccuracy %>% pivot_longer(cols=c('train', 'validation'),
                    names_to='Definations',
                    values_to='Percentage')
epochsResultAccuracy <- epochsResultAccuracy %>% 
  mutate(Percentage = round(Percentage * 100, 2))

epochsResultLoss <- tibble(
  epochs = c(1:10),
  train = c(1.7624154090881348, 0.25737470388412476, 0.1196829080581665, 0.048868823796510696, 0.03255379945039749, 0.016790855675935745, 0.012283263728022575, 0.009626168757677078, 0.007322642486542463, 0.005301191005855799),
  validation = c(0.5218960046768188, 0.18979902565479279, 0.0836237370967865, 0.054363932460546494, 0.045896977186203, 0.034609224647283554, 0.03138633072376251, 0.028076760470867157, 0.022517498582601547, 0.023578153923153877)
)

epochsResultLoss <- epochsResultLoss %>% pivot_longer(cols=c('train', 'validation'),
                    names_to='Definations',
                    values_to='Percentage')

epochsResultLoss <- epochsResultLoss %>% 
  mutate(Percentage = round(Percentage * 100, 2))


Acc <- epochsResultAccuracy %>% ggplot(aes(x = epochs, y = Percentage, color = Definations, groups = Definations)) +
 geom_line(linewidth = 1,
           ) +
  scale_color_manual(
    values = c(train = "#7FC97F",
    validation = "#666666")
  ) +
  ggtitle("Training and Validation ACCURACY while Fitting in model") +
  theme_minimal() +
  theme(
    legend.position = "none",
    plot.title = element_text( hjust = 0.4, size = 10)
  )

loss <- epochsResultLoss %>% ggplot(aes(x = epochs, y = Percentage, color = Definations, groups = Definations)) +
 geom_line(size = 1) +
  scale_color_manual(
    values = c(train = "#7FC97F",
    validation = "#666666")
  ) +
  ggtitle("Training and Validation LOSS while Fitting in model") +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = .5, size = 10),
  )
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
(Acc | loss) + 
  plot_annotation(title = "Leaves Category", theme = theme(
    plot.title = element_text(hjust = 0.5, size = 20L, face = "bold")
  ))

## Accuracy and Loss

epochsResultAccuracy <- tibble(
  epochs = c(1:10),
  train = c(0.5651558041572571, 0.8654391169548035, 0.9461756348609924, 0.9815863966941833, 0.9915013909339905, 0.9957507252693176, 0.9985835552215576, 1.0, 1.0, 0.9985835552215576),
  validation = c(0.7183908224105835, 0.8275862336158752, 0.8678160905838013, 0.8678160905838013, 0.8793103694915771, 0.9137930870056152, 0.9137930870056152, 0.9252873659133911, 0.9195402264595032, 0.9252873659133911)
)
epochsResultAccuracy <- epochsResultAccuracy %>% pivot_longer(cols=c('train', 'validation'),
                    names_to='Definations',
                    values_to='Percentage')
epochsResultAccuracy <- epochsResultAccuracy %>% 
  mutate(Percentage = round(Percentage * 100, 2))

epochsResultLoss <- tibble(
  epochs = c(1:10),
  train = c(1.667818546295166, 0.3990238308906555, 0.18011310696601868, 0.09337666630744934, 0.05730747431516647, 0.032070472836494446, 0.022132962942123413, 0.014580195769667625, 0.011054443195462227, 0.009471590630710125),
  validation = c(0.7390711903572083, 0.5420188307762146, 0.42723801732063293, 0.478878378868103, 0.42655304074287415, 0.40426507592201233, 0.39441055059432983, 0.368407666683197, 0.38018521666526794, 0.4083041548728943)
)

epochsResultLoss <- epochsResultLoss %>% pivot_longer(cols=c('train', 'validation'),
                    names_to='Definations',
                    values_to='Percentage')

epochsResultLoss <- epochsResultLoss %>% 
  mutate(Percentage = round(Percentage * 100, 2))


Acc <- epochsResultAccuracy %>% ggplot(aes(x = epochs, y = Percentage, color = Definations, groups = Definations)) +
 geom_line(size = 1,
           ) +
  scale_color_manual(
    values = c(train = "#7FC97F",
    validation = "#666666")
  ) +
  ggtitle("Training and Validation ACCURACY while Fitting in model") +
  theme_minimal() +
  theme(
    legend.position = "none",
    plot.title = element_text( hjust = 0.4, size = 10)
  )
loss <- epochsResultLoss %>% ggplot(aes(x = epochs, y = Percentage, color = Definations, groups = Definations)) +
 geom_line(linewidth = 1) +
  scale_color_manual(
    values = c(train = "#7FC97F",
    validation = "#666666")
  ) +
  ggtitle("Training and Validation LOSS while Fitting in model") +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = .5, size = 10),
  )


(Acc | loss) + 
  plot_annotation(title = "Fruit Category", theme = theme(
    plot.title = element_text(hjust = 0.5, size = 20L, face = "bold")
  ))

## Accuracy and Loss

epochsResultAccuracy <- tibble(
  epochs = c(1:10),
  train = c(0.6496437191963196, 0.95961993932724, 0.9940617680549622, 0.9988123774528503, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0),
  validation = c(0.8260869383811951, 0.8888888955116272, 0.9516907930374146, 0.9613526463508606, 0.990338146686554, 0.9855072498321533, 0.9806763529777527, 0.9855072498321533, 0.990338146686554, 0.990338146686554)
)
epochsResultAccuracy <- epochsResultAccuracy %>% pivot_longer(cols=c('train', 'validation'),
                    names_to='Definations',
                    values_to='Percentage')
epochsResultAccuracy <- epochsResultAccuracy %>% 
  mutate(Percentage = round(Percentage * 100, 2))

epochsResultLoss <- tibble(
  epochs = c(1:10),
  train = c(1.4157789945602417, 0.13098226487636566, 0.02590300142765045, 0.01123075745999813, 0.005555710289627314, 0.004017434548586607, 0.0031212433241307735, 0.00268653966486454, 0.0018341781105846167, 0.0018461743602529168),
  validation = c(0.5210107564926147, 0.2624638080596924, 0.17602533102035522, 0.1257099062204361, 0.06716671586036682, 0.06309960037469864, 0.06333737820386887, 0.04452718794345856, 0.04162444546818733, 0.04105208069086075)
)

epochsResultLoss <- epochsResultLoss %>% pivot_longer(cols=c('train', 'validation'),
                    names_to='Definations',
                    values_to='Percentage')

epochsResultLoss <- epochsResultLoss %>% 
  mutate(Percentage = round(Percentage * 100, 2))


Acc <- epochsResultAccuracy %>% ggplot(aes(x = epochs, y = Percentage, color = Definations, groups = Definations)) +
 geom_line(size = 1,
           ) +
  scale_color_manual(
    values = c(train = "#7FC97F",
    validation = "#666666")
  ) +
  ggtitle("Training and Validation ACCURACY while Fitting in model") +
  theme_minimal() +
  theme(
    legend.position = "none",
    plot.title = element_text( hjust = 0.4, size = 10)
  )
loss <- epochsResultLoss %>% ggplot(aes(x = epochs, y = Percentage, color = Definations, groups = Definations)) +
 geom_line(size = 1) +
  scale_color_manual(
    values = c(train = "#7FC97F",
    validation = "#666666")
  ) +
  ggtitle("Training and Validation LOSS while Fitting in model") +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = .5, size = 10),
  )


(Acc | loss) + 
  plot_annotation(title = "Pest Category", theme = theme(
    plot.title = element_text(hjust = 0.5, size = 20L, face = "bold")
  ))

Leaves_barGraph_Acc_Loss <- tibble(
  Identification = c("Train", "Validation"),
  Accuracy = c(100, 99.02),
  Loss = c(0.53, 2.36)
)

acc <- Leaves_barGraph_Acc_Loss %>% 
  ggplot(aes(x = Identification, y = Accuracy))+
  geom_col(width = 0.4, fill = "#228B22")+
  geom_text(aes(label = paste(Accuracy, "%")), nudge_y = 5)+
  labs(
    title = "Accuracy",
    y = "",
    x = ""
  )+
  theme_minimal() +
  theme(
      plot.title = element_text( hjust = 0.4, size = 12)
  )

Loss <- Leaves_barGraph_Acc_Loss %>% 
  ggplot(aes(x = Identification, y = Loss))+
  geom_col(width = 0.4, fill = "red")+
  geom_text(aes(label = paste(Loss, "%")), nudge_y = 5)+
  labs(
    title = "Loss",
    y = "",
    x = ""
  )+
  theme_minimal()+
  theme(
      plot.title = element_text( hjust = 0.4, size = 12)
  )

(acc | Loss) + 
  plot_annotation(title = "Leaf Category", theme = theme(
    plot.title = element_text(hjust = 0.5, size = 20L, face = "bold")
  ))

Leaves_barGraph_Acc_Loss <- tibble(
  Identification = c("Train", "Validation"),
  Accuracy = c(100, 99.03),
  Loss = c(0.18, 4.1)
)

acc <- Leaves_barGraph_Acc_Loss %>% 
  ggplot(aes(x = Identification, y = Accuracy))+
  geom_col(width = 0.4, fill = "#228B22")+
  geom_text(aes(label = paste(Accuracy, "%")), nudge_y = 5)+
  labs(
    title = "Accuracy",
    y = "",
    x = ""
  )+
  theme_minimal() +
  theme(
      plot.title = element_text( hjust = 0.4, size = 12)
  )

Loss <- Leaves_barGraph_Acc_Loss %>% 
  ggplot(aes(x = Identification, y = Loss))+
  geom_col(width = 0.4, fill = "red")+
  geom_text(aes(label = paste(Loss, "%")), nudge_y = 5)+
  labs(
    title = "Loss",
    y = "",
    x = ""
  )+
  theme_minimal()+
  theme(
      plot.title = element_text( hjust = 0.4, size = 12)
  )

(acc | Loss) + 
  plot_annotation(title = "Pest Category", theme = theme(
    plot.title = element_text(hjust = 0.5, size = 20L, face = "bold")
  ))