library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0      ✔ purrr   1.0.1 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.5.0 
## ✔ readr   2.1.3      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(patchwork)

Data Number in Leaves and Fruits Category

## Leaves Category
leaves_data <- tibble(
  Disease = c("Anthracnose", "Healthy", "Powdery Mildew", "Sooty Mould"),
  NumberofLeaves = c(996, 763, 864, 897)
  )

leavesPartion <- tibble(
  Identification = c("Train", "Validation"),
  Result = c(2817, 702 )
)

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

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(91, 216, 222, 219)
  )

FruitsPartion <- 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 = 10, face = "bold")
  )


PartitionFruit <- ggplot(FruitsPartion) +
  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")
  ))

Accuracy and Losses in LEAVES and FRUIT Category

## Accuracy and Loss

epochsResultAccuracy <- tibble(
  epochs = c(1:10),
  train = c(0.7653532028198242, 0.9389421343803406, 0.9620163440704346, 0.976925790309906, 0.985445499420166, 0.9929002523422241, 0.9960951209068298, 0.9960951209068298, 0.9968051314353943, 0.9982250332832336),
  validation = c(0.9301994442939758, 0.9287749528884888, 0.9173789024353027, 0.93304842710495, 0.9529914259910583, 0.938746452331543, 0.9558404684066772, 0.9472934603691101, 0.938746452331543, 0.9472934603691101)
)
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(0.7629544734954834, 0.17627224326133728, 0.10934333503246307, 0.07596127688884735, 0.050568047910928726, 0.03420242667198181, 0.02617245726287365, 0.020855138078331947, 0.01905786246061325, 0.014482332393527031),
  validation = c(0.22358892858028412, 0.2010875791311264, 0.25203564763069153, 0.17176185548305511, 0.12636645138263702, 0.17415866255760193, 0.13960018754005432, 0.13151854276657104, 0.2158012092113495, 0.1719779521226883)
)

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)
  )
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
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 = "Leaf 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(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 = "Fruit Category", theme = theme(
    plot.title = element_text(hjust = 0.5, size = 20L, face = "bold")
  ))

Overall Accuracy and Loss of Leaves and Fruit Category

Leaves_barGraph_Acc_Loss <- tibble(
  Identification = c("Train", "Validation"),
  Accuracy = c(99.82, 94.73),
  Loss = c(1.45, 17.20)
)

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")
  ))

Fruit_barGraph_Acc_Loss <- tibble(
  Identification = c("Train", "Validation"),
  Accuracy = c(99.86, 92.53),
  Loss = c(0.95, 40.83)
)

acc <- Fruit_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 = "Fruit Category", theme = theme(
    plot.title = element_text(hjust = 0.5, size = 20L, face = "bold")
  ))