Dataset Description

View of dataset

Dataset Description

dataset Structure

'data.frame':   58 obs. of  55 variables:
 $ SlNo                  : chr  "1" "2" "3" "4" ...
 $ Category              : chr  "State" "State" "State" "State" ...
 $ StateUTCity           : chr  "Andhra Pradesh" "Arunachal Pradesh" "Assam" "Bihar" ...
 $ AlcAddict_M           : int  94 1 11 8 2 8 14 0 0 143 ...
 $ AlcAddict_F           : int  7 0 2 1 0 0 0 0 0 7 ...
 $ AlcAddict_Total       : int  101 1 13 9 2 8 14 0 0 150 ...
 $ AlcAddict_Percent     : num  1.02 0.88 0.46 1.82 0.74 0.16 0.63 0 0 1.21 ...
 $ Drowning_M            : int  316 7 258 13 39 148 68 13 11 770 ...
 $ Drowning_F            : int  341 1 122 12 33 117 14 4 3 710 ...
 $ Drowning_Total        : int  657 8 380 25 72 265 82 17 14 1480 ...
 $ Drowning_Percent      : num  6.63 7.02 13.55 5.05 26.47 ...
 $ Fire_M                : int  414 5 8 4 12 349 108 1 0 460 ...
 $ Fire_F                : int  752 4 0 66 14 603 163 7 0 696 ...
 $ Fire_Total            : int  1166 9 8 70 26 952 271 8 0 1156 ...
 $ Fire_Percent          : num  11.77 7.89 0.29 14.14 9.56 ...
 $ Hanging_M             : int  1131 48 792 46 91 625 195 37 9 2061 ...
 $ Hanging_F             : int  508 27 375 40 20 332 65 5 4 939 ...
 $ Hanging_Total         : int  1639 75 1167 86 111 957 260 42 13 3000 ...
 $ Hanging_Percent       : num  16.6 65.8 41.6 17.4 40.8 ...
 $ Poison_M              : int  3163 6 400 110 31 1392 639 165 22 3580 ...
 $ Poison_F              : int  1885 9 220 102 14 1026 253 99 47 1604 ...
 $ Poison_Total          : int  5048 15 620 212 45 2418 892 264 69 5184 ...
 $ Poison_Percent        : num  51 13.2 22.1 42.8 16.5 ...
 $ SuicidalJump_M        : int  23 0 4 2 1 41 17 7 3 143 ...
 $ SuicidalJump_F        : int  34 0 2 0 0 16 1 1 0 103 ...
 $ SuicidalJump_Total    : int  57 0 6 2 1 57 18 8 3 246 ...
 $ SuicidalJump_Percent  : num  0.57 0 0.22 0.4 0.37 1.13 0.8 2.24 2.13 1.99 ...
 $ Selfinujury_M         : int  23 0 0 1 0 14 2 0 0 21 ...
 $ SelfInjury_F          : int  21 0 2 0 0 5 0 0 0 4 ...
 $ SelfInjury_Total      : int  44 0 2 1 0 19 2 0 0 25 ...
 $ SelfInjury_Percent    : num  0.44 0 0.07 0.2 0 0.38 0.09 0 0 0.2 ...
 $ Machine_M             : int  8 0 5 0 0 2 0 0 0 5 ...
 $ Machine_F             : int  4 0 0 0 0 1 0 0 0 1 ...
 $ Machine_Total         : int  12 0 5 0 0 3 0 0 0 6 ...
 $ Machine_Percent       : num  0.12 0 0.18 0 0 0.06 0 0 0 0.05 ...
 $ SleepingPills_M       : int  71 0 5 3 2 21 0 1 0 57 ...
 $ SleepingPills_F       : int  51 0 0 2 1 15 0 0 0 55 ...
 $ SleepingPills_Total   : int  122 0 5 5 3 36 0 1 0 112 ...
 $ SleepingPillls_Percent: num  1.23 0 0.18 1.01 1.1 0.71 0 0.28 0 0.91 ...
 $ ElectricWires_M       : int  24 1 33 3 0 14 34 2 1 54 ...
 $ ElectricWires_F       : int  7 0 13 0 0 4 3 0 1 32 ...
 $ ElectricWires_Total   : int  31 1 46 3 0 18 37 2 2 86 ...
 $ ElectricWires_Percent : num  0.31 0.88 1.64 0.61 0 0.36 1.66 0.56 1.42 0.69 ...
 $ TrainFall_M           : int  555 0 57 1 0 137 188 4 0 259 ...
 $ TrainFall_F           : int  85 0 5 0 1 32 40 0 0 48 ...
 $ TrainFall_Total       : int  640 0 62 1 1 169 228 4 0 307 ...
 $ TrainFall_Percent     : num  6.46 0 2.21 0.2 0.37 ...
 $ Other_M               : int  122 0 295 42 2 78 318 1 15 363 ...
 $ Other_F               : int  141 0 97 34 4 39 93 1 11 233 ...
 $ Other_Total           : int  263 0 392 76 6 117 411 2 26 596 ...
 $ Other_Percent         : num  2.66 0 13.98 15.35 2.21 ...
 $ Total_M               : int  6021 71 1950 235 185 2856 1600 239 74 7938 ...
 $ Total_F               : int  3884 43 854 260 87 2206 633 118 67 4437 ...
 $ Total                 : int  9905 114 2804 495 272 5062 2233 357 141 12375 ...
 $ Total_Percent         : int  100 100 100 100 100 100 100 100 100 100 ...

Summary

     SlNo             Category         StateUTCity         AlcAddict_M     
 Length:58          Length:58          Length:58          Min.   :   0.00  
 Class :character   Class :character   Class :character   1st Qu.:   0.00  
 Mode  :character   Mode  :character   Mode  :character   Median :   3.50  
                                                          Mean   :  66.48  
                                                          3rd Qu.:  18.50  
                                                          Max.   :1200.00  
  AlcAddict_F  AlcAddict_Total   AlcAddict_Percent   Drowning_M     
 Min.   :  0   Min.   :   0.00   Min.   : 0.000    Min.   :   0.00  
 1st Qu.:  0   1st Qu.:   0.00   1st Qu.: 0.000    1st Qu.:   3.25  
 Median :  0   Median :   3.50   Median : 0.640    Median :  12.00  
 Mean   : 12   Mean   :  78.48   Mean   : 1.134    Mean   : 263.02  
 3rd Qu.:  0   3rd Qu.:  18.50   3rd Qu.: 1.300    3rd Qu.:  96.75  
 Max.   :232   Max.   :1432.00   Max.   :18.420    Max.   :4839.00  
   Drowning_F      Drowning_Total    Drowning_Percent     Fire_M       
 Min.   :   0.00   Min.   :   0.00   Min.   : 0.000   Min.   :   0.00  
 1st Qu.:   1.00   1st Qu.:   5.25   1st Qu.: 2.228   1st Qu.:   3.25  
 Median :   8.00   Median :  18.00   Median : 5.145   Median :  16.00  
 Mean   : 199.57   Mean   : 462.59   Mean   : 6.109   Mean   : 227.34  
 3rd Qu.:  66.75   3rd Qu.: 157.25   3rd Qu.: 8.210   3rd Qu.: 101.25  
 Max.   :3715.00   Max.   :8554.00   Max.   :26.470   Max.   :3904.00  
     Fire_F         Fire_Total        Fire_Percent      Hanging_M      
 Min.   :   0.0   Min.   :    0.00   Min.   : 0.000   Min.   :    1.0  
 1st Qu.:   5.5   1st Qu.:    8.25   1st Qu.: 6.765   1st Qu.:   34.0  
 Median :  40.0   Median :   54.00   Median :12.730   Median :   86.0  
 Mean   : 449.8   Mean   :  677.19   Mean   :13.755   Mean   : 1049.5  
 3rd Qu.: 219.5   3rd Qu.:  304.75   3rd Qu.:18.775   3rd Qu.:  586.2  
 Max.   :7701.0   Max.   :11605.00   Max.   :39.950   Max.   :18898.0  
   Hanging_F       Hanging_Total     Hanging_Percent    Poison_M        
 Min.   :   0.00   Min.   :    3.0   Min.   : 9.22   Min.   :     0.00  
 1st Qu.:  15.75   1st Qu.:   47.0   1st Qu.:21.26   1st Qu.:     9.25  
 Median :  33.00   Median :  113.5   Median :30.11   Median :    91.50  
 Mean   : 523.36   Mean   : 1572.8   Mean   :34.99   Mean   :  3297.64  
 3rd Qu.: 278.00   3rd Qu.:  857.0   3rd Qu.:41.88   3rd Qu.:   577.75  
 Max.   :9409.00   Max.   :28307.0   Max.   :92.16   Max.   :136207.00  
    Poison_F        Poison_Total     Poison_Percent  SuicidalJump_M  
 Min.   :    0.0   Min.   :    0.0   Min.   : 0.00   Min.   :  0.00  
 1st Qu.:   10.5   1st Qu.:   21.5   1st Qu.:18.22   1st Qu.:  1.00  
 Median :   50.0   Median :  152.0   Median :29.86   Median :  4.00  
 Mean   :  839.7   Mean   : 2233.9   Mean   :28.64   Mean   : 42.59  
 3rd Qu.:  244.8   3rd Qu.:  824.0   3rd Qu.:38.49   3rd Qu.: 22.00  
 Max.   :15633.0   Max.   :41440.0   Max.   :73.95   Max.   :728.00  
 SuicidalJump_F   SuicidalJump_Total SuicidalJump_Percent Selfinujury_M   
 Min.   :  0.00   Min.   :   0.00    Min.   : 0.000       Min.   :  0.00  
 1st Qu.:  0.00   1st Qu.:   1.00    1st Qu.: 0.220       1st Qu.:  0.00  
 Median :  1.00   Median :   4.00    Median : 0.920       Median :  1.00  
 Mean   : 23.79   Mean   :  66.38    Mean   : 1.503       Mean   : 15.26  
 3rd Qu.:  6.75   3rd Qu.:  34.00    3rd Qu.: 1.988       3rd Qu.:  5.00  
 Max.   :426.00   Max.   :1154.00    Max.   :10.530       Max.   :241.00  
  SelfInjury_F     SelfInjury_Total SelfInjury_Percent   Machine_M    
 Min.   :  0.000   Min.   :  0.00   Min.   : 0.0000    Min.   :  0.0  
 1st Qu.:  0.000   1st Qu.:  0.00   1st Qu.: 0.0000    1st Qu.:  0.0  
 Median :  0.000   Median :  1.00   Median : 0.1000    Median :  0.0  
 Mean   :  9.897   Mean   : 25.16   Mean   : 0.9609    Mean   : 10.6  
 3rd Qu.:  2.750   3rd Qu.:  6.00   3rd Qu.: 0.4775    3rd Qu.:  2.0  
 Max.   :150.000   Max.   :391.00   Max.   :23.9700    Max.   :173.0  
   Machine_F     Machine_Total    Machine_Percent   SleepingPills_M 
 Min.   : 0.00   Min.   :  0.00   Min.   : 0.0000   Min.   :  0.00  
 1st Qu.: 0.00   1st Qu.:  0.00   1st Qu.: 0.0000   1st Qu.:  0.00  
 Median : 0.00   Median :  0.00   Median : 0.0000   Median :  2.50  
 Mean   : 4.19   Mean   : 14.79   Mean   : 0.3441   Mean   : 30.93  
 3rd Qu.: 0.00   3rd Qu.:  2.00   3rd Qu.: 0.1175   3rd Qu.: 11.75  
 Max.   :65.00   Max.   :238.00   Max.   :14.6100   Max.   :544.00  
 SleepingPills_F  SleepingPills_Total SleepingPillls_Percent ElectricWires_M
 Min.   :  0.00   Min.   :   0.00     Min.   : 0.000         Min.   :  0.0  
 1st Qu.:  0.00   1st Qu.:   0.00     1st Qu.: 0.000         1st Qu.:  0.0  
 Median :  1.00   Median :   3.50     Median : 0.455         Median :  2.0  
 Mean   : 25.83   Mean   :  56.76     Mean   : 1.266         Mean   : 28.9  
 3rd Qu.:  6.00   3rd Qu.:  17.25     3rd Qu.: 1.195         3rd Qu.: 12.0  
 Max.   :476.00   Max.   :1020.00     Max.   :18.750         Max.   :526.0  
 ElectricWires_F   ElectricWires_Total ElectricWires_Percent  TrainFall_M     
 Min.   :  0.000   Min.   :  0.00      Min.   :0.0000        Min.   :   0.00  
 1st Qu.:  0.000   1st Qu.:  0.00      1st Qu.:0.0000        1st Qu.:   0.00  
 Median :  0.000   Median :  2.00      Median :0.3700        Median :   2.00  
 Mean   :  8.707   Mean   : 37.60      Mean   :0.5486        Mean   : 139.72  
 3rd Qu.:  2.750   3rd Qu.: 15.25      3rd Qu.:0.6800        3rd Qu.:  56.75  
 Max.   :163.000   Max.   :689.00      Max.   :2.9700        Max.   :2664.00  
  TrainFall_F     TrainFall_Total  TrainFall_Percent    Other_M      
 Min.   :  0.00   Min.   :   0.0   Min.   : 0.000    Min.   :   0.0  
 1st Qu.:  0.00   1st Qu.:   0.0   1st Qu.: 0.000    1st Qu.:   0.0  
 Median :  0.00   Median :   3.0   Median : 0.320    Median :   6.5  
 Mean   : 35.97   Mean   : 175.2   Mean   : 1.936    Mean   : 290.4  
 3rd Qu.: 16.25   3rd Qu.:  71.0   3rd Qu.: 2.138    3rd Qu.: 119.2  
 Max.   :682.00   Max.   :3346.0   Max.   :33.010    Max.   :5486.0  
    Other_F         Other_Total     Other_Percent       Total_M       
 Min.   :   0.00   Min.   :   0.0   Min.   : 0.000   Min.   :    8.0  
 1st Qu.:   0.00   1st Qu.:   0.0   1st Qu.: 0.000   1st Qu.:   77.5  
 Median :   3.00   Median :   8.5   Median : 3.250   Median :  259.5  
 Mean   : 188.02   Mean   : 478.4   Mean   : 6.889   Mean   : 3614.6  
 3rd Qu.:  83.75   3rd Qu.: 210.2   3rd Qu.:11.265   3rd Qu.: 1862.5  
 Max.   :3563.00   Max.   :9049.0   Max.   :41.330   Max.   :66032.0  
    Total_F            Total          Total_Percent
 Min.   :    4.0   Min.   :    12.0   Min.   :100  
 1st Qu.:   50.0   1st Qu.:   131.2   1st Qu.:100  
 Median :  175.5   Median :   473.5   Median :100  
 Mean   : 2340.0   Mean   :  5954.6   Mean   :100  
 3rd Qu.:  818.0   3rd Qu.:  2661.2   3rd Qu.:100  
 Max.   :42561.0   Max.   :108593.0   Max.   :100  

univariate Analysis

Histogram-I (Total Suicides)

Histogram-II (Types of Suicides(1-6))

Histogram-III (Types of Suicides(7-12)

Suicides(Citywise)

Suicides(Statewise)

Suicides(UTwise)

Boxplot(Male)

Boxplot(Female)

Types_of_Suicide

---
title: "Exploratary data analysis for Suicide data set"
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
    theme: journal
    social: menu
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(dplyr)
library(ggplot2)
library(gridExtra)
library(tidyr)
library(reshape2)
library(DT)

data <- read.csv("Suicides_Table_26_2000.csv", stringsAsFactors = FALSE)
#View(data)



# Check for missing values

#colSums(is.na(data))

# Remove rows with missing values
data <- na.omit(data)

#Renaming


names(data) <- gsub(" ", "_", names(data)) #Remove underscores

names(data) <- gsub("[^[:alnum:]_]", "", names(data))  # Remove non-alphanumeric characters

data <- data %>% rename(AlcAddict_M = ByOverAlcoholismMale,
                        AlcAddict_F = ByOverAlcoholismFemale,
                        AlcAddict_Total = ByOverAlcoholismTotal,
                        AlcAddict_Percent=ByOverAlcoholismPercentageshare,
                        
                        Drowning_M = ByDrowningMale,
                        Drowning_F = ByDrowningFemale,                                 
                        Drowning_Total = ByDrowningTotal  ,                               
                        Drowning_Percent = ByDrowningPercentageshare,                      
                        
                        Fire_M =ByFireSelfImmolationMale,                         
                        Fire_F = ByFireSelfImmolationFemale,                       
                        Fire_Total = ByFireSelfImmolationTotal   ,                
                        Fire_Percent = ByFireSelfImmolationPercentageshare ,             
                        
                        Hanging_M = ByHangingMale,                                    
                        Hanging_F = ByHangingFemale,                                 
                        Hanging_Total = ByHangingTotal,                                   
                        Hanging_Percent= ByHangingPercentageshare,                         
                        
                        Selfinujury_M=BySelfInflictionofInjuryMale,
                        SelfInjury_F = BySelfInflictionofInjuryFemale,                   
                        SelfInjury_Total = BySelfInflictionofInjuryTotal,                   
                        SelfInjury_Percent = BySelfInflictionofInjuryPercentageshare,
                        
                        Machine_M = ByMachineMale,                                   
                        Machine_F = ByMachineFemale,                                  
                        Machine_Total = ByMachineTotal,                                   
                        Machine_Percent = ByMachinePercentageshare, 
                        
                        SleepingPills_M = ByOverdoseofSleepingPillsMale,                  
                        SleepingPills_F=ByOverdoseofSleepingPillsFemale,                
                        SleepingPills_Total = ByOverdoseofSleepingPillsTotal,
                        SleepingPillls_Percent = ByOverdoseofSleepingPillsPercentageshare,
                        
                        ElectricWires_M = ByTouchingElectricWiresMale,                     
                        ElectricWires_F = ByTouchingElectricWiresFemale,                    
                        ElectricWires_Total = ByTouchingElectricWiresTotal,                     
                        ElectricWires_Percent=ByTouchingElectricWiresPercentageshare,          
                        
                        TrainFall_M = ByComingunderRunningVehiclesTrainsMale,         
                        TrainFall_F=ByComingunderRunningVehiclesTrainsFemale,       
                        TrainFall_Total=ByComingunderRunningVehiclesTrainsTotal,          
                        TrainFall_Percent=ByComingunderRunningVehiclesTrainsPercentageshare,
                        
                        Other_M = ByOtherMeansMale,                                
                        Other_F = ByOtherMeansFemale,                               
                        Other_Total = ByOtherMeansTotal,                                
                        Other_Percent = ByOtherMeansPercentageshare,
                        
                        Total_M=TotalMale,                                       
                        Total_F=TotalFemale,                                      
                        Total=Total,                                            
                        Total_Percent=TotalPercentageshare,
)


# Merge two numeric columns

data$Poison_M <- data$PoisonByConsumingInsecticdesMale + data$ByConsumingOtherPoisonMale
#View(data)

data$Poison_F <- data$PoisonByConsumingInsecticdesFemale + data$ByConsumingOtherPoisonFemale 
#View(data)

data$Poison_Total <- data$PoisonByConsumingInsecticdesTotal + data$ByConsumingOtherPoisonTotal
#View(data)

data$Poison_Percent <- data$PoisonByConsumingInsecticdesPercentageshare + data$ByConsumingOtherPoisonPercentageshare
#View(data)

data$SuicidalJump_M <- data$ByJumpingfromBuildingMale + data$ByJumpingfromOtherSitesMale
#View(data)

data$SuicidalJump_F <- data$ByJumpingfromBuildingFemale + data$ByJumpingfromOtherSitesFemale
#View(data)

data$SuicidalJump_Total <- data$ByJumpingfromBuildingTotal + data$ByJumpingfromOtherSitesTotal
#View(data)

data$SuicidalJump_Percent <- data$ByJumpingfromBuildingPercentageshare + data$ByJumpingfromOtherSitesPercentageshare
#View(data)


# Define mergedcolumns to their new positions
columns_to_move <- c("Poison_M", "Poison_F","Poison_Total","Poison_Percent","SuicidalJump_M","SuicidalJump_F","SuicidalJump_Total","SuicidalJump_Percent")
new_positions <- c(26,27,28,29,30,31,32,33)

# Get current column names
cols <- names(data)

# Remove columns to move from their current positions
cols <- setdiff(cols, columns_to_move)

# Insert columns into new positions
for (i in seq_along(columns_to_move)) {
  cols <- append(cols, columns_to_move[i], after = new_positions[i] - 1)
}
# Reorder the data frame
data <- data[, cols]


#delete merged cols

cleaned_data <- data %>% select(-PoisonByConsumingInsecticdesMale,-PoisonByConsumingInsecticdesFemale,-PoisonByConsumingInsecticdesTotal,-PoisonByConsumingInsecticdesPercentageshare,-ByConsumingOtherPoisonMale,-ByConsumingOtherPoisonFemale,-ByConsumingOtherPoisonTotal,-ByConsumingOtherPoisonPercentageshare, -ByJumpingfromBuildingMale,-ByJumpingfromBuildingFemale,-ByJumpingfromBuildingTotal,-ByJumpingfromBuildingPercentageshare,-ByJumpingfromOtherSitesMale,-ByJumpingfromOtherSitesFemale,-ByJumpingfromOtherSitesTotal,-ByJumpingfromOtherSitesPercentageshare,-ByJumpingoffMovingVehiclesTrainsMale,-ByJumpingoffMovingVehiclesTrainsFemale,-ByJumpingoffMovingVehiclesTrainsTotal,-ByJumpingoffMovingVehiclesTrainsPercentageshare,-ByFireArmsMale,-ByFireArmsFemale,-ByFireArmsTotal,-ByFireArmsPercentageshare )


```


## Dataset Description {.tabset}
### View of dataset
```{r}
  datatable(cleaned_data, extensions = 'Buttons' ,options = list(dom='Bfrtip',Buttons=c('copy','print','PDF','csv')))
```

## Dataset Description {.tabset}
### dataset Structure

```{r}
    str(cleaned_data)
```

### Summary

```{r}
summary(cleaned_data)

```

## univariate Analysis {.tabset}
### Histogram-I (Total Suicides)

```{r}
ggplot(cleaned_data, aes(x = Total)) + 
  geom_histogram(color = "black", fill = "lightblue", binwidth = 100) + 
  labs(title = "Histogram of Total Suicides", x = "Total Suicides", y = "Frequency")


```

### Histogram-II (Types of Suicides(1-6))

```{r}

plot_1 <- ggplot(cleaned_data, aes(x = AlcAddict_Total)) + 
  geom_histogram(color = "black", fill = "lightblue", binwidth = 10) + 
  labs(title = "Alcohol Addiction Suicides", x = "Alcohol Addiction Suicides", y = "Frequency")

plot_2 <- ggplot(cleaned_data, aes(x = Drowning_Total)) + 
  geom_histogram(color = "black", fill = "lightblue", binwidth = 10) + 
  labs(title = "Drowning Suicides", x = "Drowning Suicides", y = "Frequency")

plot_3 <- ggplot(cleaned_data, aes(x = Fire_Total)) + 
  geom_histogram(color = "black", fill = "lightblue", binwidth = 10) + 
  labs(title = "Fire Suicides", x = "Fire Suicides", y = "Frequency")

plot_4 <- ggplot(cleaned_data, aes(x = Hanging_Total)) + 
  geom_histogram(color = "black", fill = "lightblue", binwidth = 10) + 
  labs(title = "Hanging Suicides", x = "Hanging Suicides", y = "Frequency")

plot_5 <- ggplot(cleaned_data, aes(x = Poison_Total)) + 
  geom_histogram(color = "black", fill = "lightblue", binwidth = 10) + 
  labs(title = "Poison Suicides", x = "Poison Suicides", y = "Frequency")

plot_6 <- ggplot(cleaned_data, aes(x = SelfInjury_Total)) + 
  geom_histogram(color = "black", fill = "lightblue", binwidth = 10) + 
  labs(title = "Self-Injury Suicides", x = "Self-Injury Suicides", y = "Frequency")

grid.arrange(plot_1, plot_2, plot_3, plot_4, plot_5, plot_6, ncol = 3)

```

### Histogram-III (Types of Suicides(7-12)
```{r}

plot_7 <- ggplot(cleaned_data, aes(x = Machine_Total)) + 
  geom_histogram(color = "black", fill = "lightblue", binwidth = 10) + 
  labs(title = "Machine Suicides", x = "Machine Suicides", y = "Frequency")

plot_8 <- ggplot(cleaned_data, aes(x = SleepingPills_Total)) + 
  geom_histogram(color = "black", fill = "lightblue", binwidth = 10) + 
  labs(title = "Sleeping Pills Suicides", x = "Sleeping Pills Suicides", y = "Frequency")

plot_9 <- ggplot(cleaned_data, aes(x = ElectricWires_Total)) + 
  geom_histogram(color = "black", fill = "lightblue", binwidth = 10) + 
  labs(title = "Electric Wires Suicides", x = "Electric Wires Suicides", y = "Frequency")

plot_10 <- ggplot(cleaned_data, aes(x = TrainFall_Total)) + 
  geom_histogram(color = "black", fill = "lightblue", binwidth = 10) + 
  labs(title = "Train Fall Suicides", x = "Train Fall Suicides", y = "Frequency")

plot_11 <- ggplot(cleaned_data, aes(x = Other_Total)) + 
  geom_histogram(color = "black", fill = "lightblue", binwidth = 10) + 
  labs(title = "Other Suicides", x = "Other Suicides", y = "Frequency")

plot_12 <- ggplot(cleaned_data, aes(x = SuicidalJump_Total)) + 
  geom_histogram(color = "black", fill = "lightblue", binwidth = 10) + 
  labs(title = "Suicidal Jump Suicides", x = "Suicidal Jump Suicides", y = "Frequency")

grid.arrange(plot_7, plot_8, plot_9, plot_10, plot_11, plot_12, ncol = 3)

```


```{r}

# Subset State, UT, City
Statewise_data <- cleaned_data %>% filter(Category == "State")
UTwise_data <- cleaned_data %>% filter(Category == "UT")
Citywise_data <- cleaned_data %>% filter(Category == "City")

# Subset Top 5 States, Cities, UTs
top_5_states <- Statewise_data %>% 
  arrange(desc(Total)) %>% 
  head(5)

top_5_uts <- UTwise_data %>% 
  arrange(desc(Total)) %>% 
  head(5)

top_5_cities <- Citywise_data %>% 
  arrange(desc(Total)) %>% 
  head(5)

# Subset data by method of suicide
alc_addict <- cleaned_data %>% filter(AlcAddict_Total > 0)
drowning <- cleaned_data %>% filter(Drowning_Total > 0)
fire <- cleaned_data %>% filter(Fire_Total > 0)
hanging <- cleaned_data %>% filter(Hanging_Total > 0)
poison <- cleaned_data %>% filter(Poison_Total > 0)
self_injury <- cleaned_data %>% filter(SelfInjury_Total > 0)
machine <- cleaned_data %>% filter(Machine_Total > 0)
sleeping_pills <- cleaned_data %>% filter(SleepingPills_Total > 0)
electric_wires <- cleaned_data %>% filter(ElectricWires_Total > 0)
train_fall <- cleaned_data %>% filter(TrainFall_Total > 0)
other <- cleaned_data %>% filter(Other_Total > 0)
suicidal_jump <- cleaned_data %>% filter(SuicidalJump_Total > 0)

```


### Suicides(Citywise)
```{r}
ggplot(Citywise_data, aes(x = reorder(StateUTCity, Total), y = Total)) +
  geom_point(aes(color = Total), size = 3) +
  labs(title = "Scatter Plot of Suicides by City", x = "City", y = "Total Suicides") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +  
  scale_color_viridis_c()
```

### Suicides(Statewise)
```{r}
ggplot(Statewise_data, aes(x = reorder(StateUTCity, Total), y = Total)) +
  geom_point(aes(color = Total), size = 3) +
  labs(title = "Scatter Plot of Suicides by States", x = "State", y = "Total Suicides") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +  
  scale_color_viridis_c()

```

###  Suicides(UTwise)
```{r}
ggplot(UTwise_data, aes(x = reorder(StateUTCity, Total), y = Total)) +
  geom_point(aes(color = Total), size = 3) +
  labs(title = "Scatter Plot of Suicides by UT", x = "UT", y = "Total Suicides") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +  
  scale_color_viridis_c()

```

### Boxplot(Male)
```{r}
ggplot(cleaned_data, aes(x = "", y = Total_M)) + 
  geom_boxplot(fill = "lightblue") + 
  labs(title = "Box Plot of Male Suicides", x = "", y = "Number of Male Suicides") + 
  theme_minimal() +
  theme(axis.title.x = element_blank(), axis.text.x = element_blank())

```

### Boxplot(Female)
```{r}
ggplot(cleaned_data, aes(x = "", y = Total_F)) + 
  geom_boxplot(fill = "lightblue") + 
  labs(title = "Box Plot of Female Suicides", x = "", y = "Number of Female Suicides") + 
  theme_minimal() +
  theme(axis.title.x = element_blank(), axis.text.x = element_blank())

```

###  Types_of_Suicide
```{r}
totals_long <- cleaned_data %>%
  select(contains("_Total")) %>%  
  pivot_longer(
    cols = everything(),         
    names_to = "Method",         
    values_to = "Total"      
  ) %>%
  
  mutate(Method = gsub("_Total", "", Method)) %>%
  
  mutate(Total = as.numeric(Total)) %>%
  
  select(Method, Total)

totals_long_filtered <- totals_long %>%
  filter(Total > 0) 

totals_long_filtered <- totals_long_filtered %>%
  filter(Total < 10000)

ggplot(totals_long_filtered, aes(x = reorder(Method, -Total), y = Total)) + 
  geom_bar(stat = "identity", fill = "salmon") + 
  labs(title = "Total Suicides by Method", x = "Method", y = "Total Suicides") + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1))  # Rotate x-axis labels for readability

```