INTRODUCTION

Financial analysis plays a vital role in assessing a company’s stability, profitability, and overall performance. This study focuses on a comparative analysis of Tata Motors and Mahindra & Mahindra, evaluating their financial strengths and weaknesses through key ratios. Additionally, an in-depth DuPont analysis is conducted for both companies to break down their return on equity (ROE) and identify key drivers of financial performance. This comprehensive assessment provides valuable insights into their competitive standing in the automobile industry.

This report is structured as follows:

-Decoding the Data 🧐: A deep dive into the dataset—its sources, scope, and the key aspects shaping our analysis.

-Head-to-Head: Competitive Analysis ⚖️: A comprehensive comparison of the chosen company with its competitor, uncovering strengths, market positioning, and financial standing.

-Strengths & Stumbling Blocks 🔍: A critical assessment of what sets the company apart and the challenges that could hinder its growth.

-Beyond the Basics: Advanced Financial Ratios 📊: Going beyond standard metrics to explore additional financial indicators that provide a clearer picture of performance.

-Final Verdict: Insights & Strategic Roadmap 🚀: Key takeaways, major findings, and actionable recommendations to steer the company toward success.

TOPIC 1

Why Company-Level Analysis?

A focused company-level analysis provides deeper insights into the unique financial and strategic aspects of each business, unlike broad industry studies that often miss individual strengths and challenges.

In this study, we compare Tata Motors and Mahindra & Mahindra, evaluating their financial performance, organizational strategies, strengths, and weaknesses. This approach offers a direct competitive analysis, uncovering key insights for growth and improvement.

Additionally, DuPont analysis helps break down profitability drivers, enhancing our understanding of efficiency and financial health. By integrating both financial and organizational factors, this study delivers a well-rounded, actionable assessment.

Why the Automobile Industry?

The automobile industry is a key driver of economic growth, innovation, and technological advancement. It plays a crucial role in infrastructure development, job creation, and global trade. With automobiles being an essential part of daily life, analyzing this sector provides valuable insights into market trends, financial stability, and competitive positioning.

For this study, we focus on Tata Motors and Mahindra & Mahindra, two leading players in the Indian automotive industry. By evaluating their financial performance, operational efficiency, and strategic strengths, we aim to understand their market positioning and future growth potential.

Why Tata Motors?

Tata Motors was chosen for our financial analysis due to its significant impact on the Indian and global automobile industry. Despite intense competition, Tata Motors has demonstrated consistent growth, innovation, and resilience, especially during challenging periods like the COVID-19 pandemic.

Over the past five years, the company has expanded its market share, introduced high-quality, fuel-efficient, and electric vehicles, and improved profitability. While financial metrics are crucial, we also consider qualitative factors such as brand perception, customer satisfaction, and innovation, which are key drivers of long-term success in the automobile industry.

Mahindra & Mahindra as a Competitor

–> Mahindra & Mahindra is one of the leading players in the Indian automobile industry, competing directly with Tata Motors across various segments, including SUVs, commercial vehicles, and electric mobility.

–> For a comprehensive competitive analysis, it is crucial to compare financial performance with a strong industry rival. This helps assess Tata Motors’ position and identify areas for growth.

–> Mahindra & Mahindra has built a strong market presence, particularly in the SUV and tractor segments, making it a formidable competitor for Tata Motors.

–> The company also enjoys high brand loyalty, which poses a challenge for competitors, making this comparison even more insightful.

Data Overview

Comparative financial analysis

For this study, we have selected Tata Motors and Mahindra & Mahindra, two of the leading players in the Indian automobile industry.

The analysis focuses on four major financial aspects:

Liquidity Ratios

These ratios measure the companies’ ability to meet short-term obligations:

Current Ratio – Assesses the company’s ability to pay short-term liabilities with current assets.

Quick Ratio – Evaluates liquidity by excluding inventory, focusing on highly liquid assets.

Profitability Ratios

These ratios help determine how efficiently each company generates profits:

Net Profit Margin – Measures the percentage of revenue converted into net profit.

Activity Ratios

These ratios analyze operational efficiency and asset utilization:

Asset Turnover Ratio – Indicates how effectively assets are used to generate revenue.

Inventory Turnover Ratio – Measures how efficiently inventory is managed and sold.

Solvency Ratios

These ratios evaluate financial stability and debt management:

Debt to Equity Ratio – Shows the proportion of debt used to finance the company relative to equity.

This structured approach allows us to compare Tata Motors and Mahindra & Mahindra comprehensively, identifying their strengths, weaknesses, and areas for improvement in the competitive automobile industry.

Weaknesses and Strengths Analysis

For this study, we assess the financial strengths and weaknesses of Tata Motors

Weaknesses

Liquidity Ratio

Quick Ratio – Evaluates short-term liquidity by excluding inventory. A lower ratio may indicate reliance on inventory for covering liabilities.

Solvency Ratio

Debt to Equity Ratio – Measures financial leverage. A higher ratio suggests increased dependence on debt financing, which may pose financial risk.

Profitability Ratio

Net Profit Margin – Indicates profitability. A lower margin suggests higher costs, operational inefficiencies, or pricing challenges.

Strengths

Liquidity Ratios

Current Ratio – Assesses the ability to meet short-term obligations. A higher ratio indicates strong liquidity.

Cash Ratio – Measures cash reserves available to cover liabilities. A high ratio suggests financial stability.

Solvency Ratio

Financial Leverage – Reflects how effectively a company uses debt to enhance returns while maintaining financial stability.

Profitability Ratio

Gross Profit Margin – Assesses cost efficiency and pricing power. A high margin indicates strong revenue generation relative to production costs.

This comparative evaluation helps understand where each company excels and where improvements are needed in the Indian automobile industry.

Other Key Metrics

In addition to the core financial ratios, we will also analyze:

CSR Ratio – Assessing corporate social responsibility spending.

Cash Flow Analysis – Understanding liquidity and cash generation.

DuPont Analysis – Breaking down ROE into profitability, efficiency, and leverage components.

Head-to-Head: Competitive Analysis ⚖️

LIQUIDITY

TATA MOTORS CURRENT RATIO

BY GOUTHAM S

#load the packages
library(readxl)
## Warning: package 'readxl' was built under R version 4.4.3
library(gridExtra)
## Warning: package 'gridExtra' was built under R version 4.4.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.3
#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Current Ratio
#Current Ratio = current Asset/current Liability
#First Step --> Current Asset

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
cr1_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Cash_CE",])

crp1_tata=ggplot(cr1_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Cash & Cash Equivalents",
       caption = "Cleaned by Team",
       subtitle= "TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1200, 5400),  # Set y-axis limits
    breaks = seq(1200, 5400, by = 600),  # Set the breaks on the y-axis
    labels = seq(12, 54, by = 6), # Label the y-axis with values from 12 to 54
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
cr2_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="CurInvst",])

crp2_tata=ggplot(cr2_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Current Investments",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(600, 5400),  # Set y-axis limits
    breaks = seq(600, 5400, by = 800),  # Set the breaks on the y-axis
    labels = seq(6, 54, by = 8), # Label the y-axis with values from 6 to 54
  ) + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
cr3_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Inv",])

crp3_tata=ggplot(cr3_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Inventory",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(2500, 5000),  # Set y-axis limits
    breaks = seq(2500, 5000, by = 500),  # Set the breaks on the y-axis
    labels = seq(25, 50, by = 5), # Label the y-axis with values from 25 to 50
) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
cr4_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="OCurrAst",])

crp4_tata=ggplot(cr4_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Other Current Asset",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1200, 3300),  # Set y-axis limits
    breaks = seq(1200, 3300, by = 300),  # Set the breaks on the y-axis
    labels = seq(12, 33, by = 3),# Label the y-axis with values from 12 to 33
 ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 5
cr5_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="ST_LoanAdv",])

crp5_tata=ggplot(cr5_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Short-Term Loans & Advances",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(120, 240),  # Set y-axis limits
    breaks = seq(120, 240, by = 20),  # Set the breaks on the y-axis
    labels = seq(120, 240, by = 20),# Label the y-axis with values from 120 to 240
) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 6
cr6_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="TR",])

crp6_tata=ggplot(cr6_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Trade Receivables",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1900, 2900),  # Set y-axis limits
    breaks = seq(1900, 2900, by = 200),  # Set the breaks on the y-axis
    labels = seq(19, 29, by = 2),# Label the y-axis with values from 19 to 29
)  +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )  

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Current Assets

grid.arrange(crp1_tata,crp2_tata,crp3_tata,crp4_tata,crp5_tata,crp6_tata,nrow=3,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Pie chart
library(ggplot2)
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.3
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:gridExtra':
## 
##     combine
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
# Filtering Current Assets from the tata_bs_long
current_assets <- tata_bs_long[tata_bs_long$Items %in% c("CurInvst", "Inv", "TR", "Cash_CE", "OCurrAst","ST_LoanAdv"), ]

# Filter for the last 5 years and sum amounts by Items
current_assets_total <- current_assets %>%
  filter(Year %in% c(2024, 2023, 2022, 2021, 2020)) %>%  # Keeping only required years
  group_by(Items) %>%  # Group by Items
  summarise(Total_Amount = sum(Amount, na.rm = TRUE))  # Adding Amount column

# correct labels
item_labels <- c(
  "CurInvst" = "Current Investments",
  "Inv" = "Inventory",
  "TR" = "Trade Receivables",
  "Cash_CE" = "Cash & Cash Equivalents",
  "ST_LoanAdv" = "Short-Term Loans & Advances",
  "OCurrAst" = "Other Current Assets"
)

# Pie Chart for Total Current Assets Distribution
ggplot(current_assets_total, aes(x = "", y = Total_Amount, fill = Items)) +
  geom_bar(stat = "identity", width = 2.5, color = "black") +  # Outline added
  coord_polar(theta = "y") +  
  labs(title = "Total Current Assets Distribution (2020-2024)", fill = "Items") +
  
  # Custom Colors
  scale_fill_manual(values = c(
    "CurInvst" = "yellow", 
    "Inv" = "lightblue",   
    "TR" = "green",  
    "Cash_CE" = "grey",    
    "ST_LoanAdv" = "hotpink", 
    "OCurrAst" = "orange" 
  )) + 
  
  # Labels inside the pie chart (Centred)
  geom_text(aes(label = paste0(item_labels[Items], "\n", 
                               round((Total_Amount / sum(Total_Amount)) * 100, 1), "%")), 
            position = position_stack(vjust = 0.5), 
            size = 3.5, color = "black", fontface = "bold") +
  theme_minimal() +
  theme(
    axis.title = element_blank(),
    axis.text = element_blank(),
    panel.grid = element_blank(),
    plot.title = element_text(hjust = 0.5, face = "bold", size = 15)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Current ratio = current asset/current liability
#Second Step --> current Liability

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 7
cr7_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="OCurrLiab",])

crp7_tata=ggplot(cr7_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Other Current Liability",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(8000, 12000),  # Set y-axis limits
    breaks = seq(8000, 12000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(8, 12, by = 1),# Label the y-axis with values from 8 to 12
) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 8
cr8_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="STBor",])

crp8_tata=ggplot(cr8_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Short-Term Borrowings",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(5000, 10000),  # Set y-axis limits
    breaks = seq(5000, 10000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(5, 10, by = 1),# Label the y-axis with values from 5 to 10
) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 9
cr9_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="STProv",])

crp9_tata=ggplot(cr9_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Short-Term Provisions",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(300, 1500),  # Set y-axis limits
    breaks = seq(300, 1500, by = 300),  # Set the breaks on the y-axis
    labels = seq(3, 15, by = 3), # Label the y-axis with values from 3 to 15
) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 10
cr10_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="TP",])

crp10_tata=ggplot(cr10_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Trade Payables",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(5000, 10000),  # Set y-axis limits
    breaks = seq(5000, 10000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(5, 10, by = 1), # Label the y-axis with values from 5 to 10
) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )   
#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - total Liability

grid.arrange(crp7_tata,crp8_tata,crp9_tata,crp10_tata,nrow=2,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Pie chart
library(ggplot2)
library(dplyr)

# Filtering Current Liabilities from the tata_bs_long
current_liabilities <- tata_bs_long[tata_bs_long$Items %in% c("STBor", "TP", "OCurrLiab", "STProv"), ]

# Filter for the last 5 years and sum amounts by Items
current_liablities_total <- current_liabilities %>%
  filter(Year %in% c(2024, 2023, 2022, 2021, 2020)) %>%  # Keeping only required years
  group_by(Items) %>%  # Group by Items
  summarise(Total_Amount = sum(Amount, na.rm = TRUE))  # Adding Amount column

library(plotrix)

# pie chart input
items <- c("Current Investment", "Inventory", "Trade Receivables", "Cash and Cash Equivalents", "Short-Term Loans and Advances", "Other Current Assets")
values <- c(200, 300, 150, 250, 180, 220)  # Example total amounts
colors <- c("yellow", "lightblue", "green", "grey", "hotpink", "orange")

# 3D Pie Chart
pie3D(values, labels = paste0(items, "\n", round(values / sum(values) * 100, 1), "%"),
      col = colors, explode = 0.05, main = "Total Current Assets Distribution (2020-2024)")

#-----------------------------------------------------------------------------------------------------------------------------------------------------

tata_bs_long<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
# Inspect the data structure
head(tata_bs_long)
Items 2024 2023 2022 2021 2020 Category
EqShCap 766.50 766.02 765.88 765.81 719.54 SholderFunds
Res_Surp 29374.83 21701.37 19171.88 18290.16 16800.61 SholderFunds
EqShApMony 1.72 2.46 6.39 0.00 0.00 SholderFunds
LTBor 5235.67 10445.70 14102.74 16326.77 14776.51 NonCurLiab
DTL_Net 49.78 51.16 173.72 266.50 198.59 NonCurLiab
Other_LTB 1392.16 1411.78 1212.34 1786.93 1646.56 NonCurLiab
# Filtering Current Assets from the tata_bs_long
current_assets <- tata_bs_long[tata_bs_long$Items %in% c("CurInvst", "Inv", "TR", "Cash_CE", "OCurrAst","ST_LoanAdv"), ]

# Filtering Current Liabilities from the tata_bs_long
current_liabilities <- tata_bs_long[tata_bs_long$Items %in% c("STBor", "TP", "OCurrLiab", "STProv"), ]

# Sum Current Assets and Current Liabilities for each year 2024 to 2020
current_assets_sum <- colSums(current_assets[, 2:6]) 
current_liabilities_sum <- colSums(current_liabilities[,2:6])  

# Calculate Current Ratio
current_ratio <- current_assets_sum / current_liabilities_sum

# Displaying the Current Ratio
current_ratio
##      2024      2023      2022      2021      2020 
## 0.5565242 0.4456735 0.5786582 0.6039487 0.5257005
# Create a data frame for plotting
current_ratio_data <- data.frame(
  Year = as.numeric(names(current_ratio)),  # Extract year names
  Current_Ratio = as.numeric(current_ratio) # Convert ratios to numeric
)

# Plot = Current Ratio
ggplot(current_ratio_data, aes(x = Year, y = Current_Ratio)) +
  geom_line(color = "red", linewidth = 1.5) +  # Use linewidth for line thickness
  geom_point(color = "blue", size = 3.5) +        # Add points for each year
  labs(
    title = "Current Ratio Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Current Ratio"
  ) +
  scale_y_continuous(
    limits = c(0.42, 0.62), # Set y-axis limits
    breaks = seq(0.42, 0.62, by = 0.04), # Set the breaks on the y-axis
    labels = scales::label_number(accuracy = 0.01), # Label the y-axis with values from 0.42 to 0.62
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load required libraries
library(ggplot2)

# Create bar plot
ggplot(current_ratio_data, aes(x = factor(Year), 
                               y = Current_Ratio, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(title = "Current Ratio from (2020 - 2024)", x = "Year",
       y = "Current Ratio") +
  scale_fill_manual(values = c("2024" = "blue", "2023" = "red",
                               "2022" = "green", "2021" = "navy", "2020" = "orange")) +
  geom_text(aes(label = round(Current_Ratio, 2)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(0, 0.65), # Set y-axis limits
    breaks = seq(0, 0.65, by = 0.05), # Set the breaks on the y-axis
    labels = scales::label_number(accuracy = 0.01), # Label the y-axis with values from 0.40 to 0.70
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

LIQUIDITY

MAHINDRA & MAHINDRA LTD CURRENT RATIO

BY GOUTHAM S

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
mahindra_bs<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
mahindra_bs<-as.data.frame(mahindra_bs)

#clean the column names
colnames(mahindra_bs)<-make.names(colnames(mahindra_bs))
colnames(mahindra_bs)<-trimws(colnames(mahindra_bs))

#reshaping the data to long format
mahindra_bs_long<-reshape(mahindra_bs,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(mahindra_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Current Ratio
#Current Ratio = current Asset/current Liability
#First Step --> Current Asset

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
cr1_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="Cash_CE",])

crp1_mahindra=ggplot(cr1_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="green",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Cash & Cash Equivalents",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(3000, 7000),  # Set y-axis limits
    breaks = seq(3000, 7000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(3, 7, by = 1), # Label the y-axis with values from 3 to 7
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
cr2_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="CurInvst",])

crp2_mahindra=ggplot(cr2_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="green",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Current Investments",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1500, 10500),  # Set y-axis limits
    breaks = seq(1500, 10500, by = 1500),  # Set the breaks on the y-axis
    labels = seq(1.5, 10.5, by = 1.5), # Label the y-axis with values from 1.5 to 10.5
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
cr3_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="Inv",])

crp3_mahindra=ggplot(cr3_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="green",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Inventory",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(3000, 10000),  # Set y-axis limits
    breaks = seq(3000, 10000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(3, 10, by = 1), # Label the y-axis with values from 3 to 10
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
cr4_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="OCurrAst",])

crp4_mahindra=ggplot(cr4_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="green",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Other Current Asset",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1000, 6000),  # Set y-axis limits
    breaks = seq(1000, 6000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(1, 6, by = 1),# Label the y-axis with values from 1 to 6
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 5
cr5_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="ST_LoanAdv",])

crp5_mahindra=ggplot(cr5_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="green",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Short-Term Loans & Advances",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(300, 2700),  # Set y-axis limits
    breaks = seq(300, 2700, by = 400),  # Set the breaks on the y-axis
    labels = seq(3, 27, by = 4),# Label the y-axis with values from 3 to 27
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )  

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 6
cr6_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="TR",])

crp6_mahindra=ggplot(cr6_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="green",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Trade Receivables",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(2000, 5000),  # Set y-axis limits
    breaks = seq(2000, 5000, by = 500),  # Set the breaks on the y-axis
    labels = seq(2, 5, by = 0.5),# Label the y-axis with values from 2 to 5
  )  +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )  

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Current Asset

grid.arrange(crp1_mahindra,crp2_mahindra,crp3_mahindra,crp4_mahindra,crp5_mahindra,crp6_mahindra,nrow=3,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Pie chart
library(ggplot2)
library(dplyr)

# Filtering Current Assets from the mahindra_bs_long
current_assets_mahindra <- mahindra_bs_long[mahindra_bs_long$Items %in% c("CurInvst", "Inv", "TR", "Cash_CE", "OCurrAst","ST_LoanAdv"), ]

# Filter for the last 5 years and sum amounts by Items
current_assets_mahindra_total <- current_assets_mahindra %>%
  filter(Year %in% c(2024, 2023, 2022, 2021, 2020)) %>%  # Keeping only required years
  group_by(Items) %>%  # Group by Items
  summarise(Total_Amount = sum(Amount, na.rm = TRUE))  # Adding Amount column

# correct labels
item_labels <- c(
  "CurInvst" = "Current Investments",
  "Inv" = "Inventory",
  "TR" = "Trade Receivables",
  "Cash_CE" = "Cash & Cash Equivalents",
  "ST_LoanAdv" = "Short-Term Loans & Advances",
  "OCurrAst" = "Other Current Assets"
)

# Pie Chart for Total Current Assets Distribution
ggplot(current_assets_mahindra_total, aes(x = "", y = Total_Amount, fill = Items)) +
  geom_bar(stat = "identity", width = 2.5, color = "black") +  # Outline added
  coord_polar(theta = "y") +  
  labs(title = "Total Current Assets Distribution (2020-2024)", fill = "Items") +
  
  # Custom Colors
  scale_fill_manual(values = c(
    "CurInvst" = "yellow", 
    "Inv" = "lightblue",   
    "TR" = "green",  
    "Cash_CE" = "grey",    
    "ST_LoanAdv" = "hotpink", 
    "OCurrAst" = "orange" 
  )) + 
  
  # Labels inside the pie chart (Centred)
  geom_text(aes(label = paste0(item_labels[Items], "\n", 
                               round((Total_Amount / sum(Total_Amount)) * 100, 1), "%")), 
            position = position_stack(vjust = 0.5), 
            size = 3, color = "black", fontface = "bold") +
  theme_minimal() +
  theme(
    axis.title = element_blank(),
    axis.text = element_blank(),
    panel.grid = element_blank(),
    plot.title = element_text(hjust = 0.5, face = "bold", size = 15)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Current ratio = current asset/current liability
#Second Step --> Current Liability

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
mahindra_bs<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
mahindra_bs<-as.data.frame(mahindra_bs)

#clean the column names
colnames(mahindra_bs)<-make.names(colnames(mahindra_bs))
colnames(mahindra_bs)<-trimws(colnames(mahindra_bs))

#reshaping the data to long format
mahindra_bs_long<-reshape(mahindra_bs,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(mahindra_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 7
cr7_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="OCurrLiab",])

crp7_mahindra=ggplot(cr7_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="green",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Other Current Liabilities",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(2500, 6500),  # Set y-axis limits
    breaks = seq(2500, 6500, by = 1000),  # Set the breaks on the y-axis
    labels = seq(2.5, 6.5, by = 1),# Label the y-axis with values from 2.5 to 6.5
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 8
cr8_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="STBor",])

crp8_mahindra=ggplot(cr8_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="green",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Short-Term Borrowings",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(0, 2500),  # Set y-axis limits
    breaks = seq(0, 2500, by = 500),  # Set the breaks on the y-axis
    labels = seq(0, 2500, by = 500),# Label the y-axis with values from 0 to 2500
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 9
cr9_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="STProv",])

crp9_mahindra=ggplot(cr9_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="green",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Short-Term Provisions",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(425, 725),  # Set y-axis limits
    breaks = seq(425, 725, by = 75),  # Set the breaks on the y-axis
    labels = seq(425, 725, by = 75), # Label the y-axis with values from 425 to 725
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )   

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 10
cr10_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="TP",])

crp10_mahindra=ggplot(cr10_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="green",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Trade Payables",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(5000, 20000),  # Set y-axis limits
    breaks = seq(5000, 20000, by = 3000),  # Set the breaks on the y-axis
    labels = seq(5, 20, by = 3), # Label the y-axis with values from 5 to 20
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )   

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Total Liability

grid.arrange(crp7_mahindra,crp8_mahindra,crp9_mahindra,crp10_mahindra,nrow=2,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Pie chart
library(ggplot2)
library(dplyr)

# Filtering Current Liabilities from the mahindra_bs_long
current_liabilities_mahindra <- mahindra_bs_long[mahindra_bs_long$Items %in% c("STBor", "TP", "OCurrLiab", "STProv"), ]

# Filter for the last 5 years and sum amounts by Items
current_liabilities_mahindra_total <- current_liabilities_mahindra %>%
  filter(Year %in% c(2024, 2023, 2022, 2021, 2020)) %>%  # Keeping only required years
  group_by(Items) %>%  # Group by Items
  summarise(Total_Amount = sum(Amount, na.rm = TRUE))  # Adding Amount column

# Load the package
library(plotrix)

# Define data (Ensure 'current_liabilities_mahindra_total' is a data frame)
liabilities_data <- current_liabilities_mahindra_total$Total_Amount
liabilities_labels <- c("Short-Term Borrowings", "Trade Payables", "Other Current Liabilities", "Short-Term Provisions")

# Define colors for the pie chart
colors <- c("orange", "green", "hotpink", "yellow")

# Create a 3D Pie Chart
pie3D(
  liabilities_data, 
  labels = paste0(liabilities_labels, "\n", round((liabilities_data / sum(liabilities_data)) * 100, 1), "%"), 
  explode = 0.1,                # Slightly separate slices for better visualization
  main = "Total Current Liabilities Distribution (2020–2024)", 
  col = colors,                 # Use custom colors
  labelcex = 1.0,               # Adjust label size
  shade = 0.6,                  # Adds shading effect for 3D appearance
  radius = 1.0,                 # Adjust pie size
  start = pi/3                 # Rotates the pie for better view
)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

mahindra_bs_long<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
# Inspect the data structure
head(mahindra_bs_long)
Items 2024 2023 2022 2021 2020 Category
EqShCap 599.62 599.05 598.30 597.39 596.52 SholderFunds
Res_Surp 51378.18 42497.35 38139.19 33649.65 33606.36 SholderFunds
EqShApMony 298.76 260.33 223.46 254.88 264.96 SholderFunds
LTBor 1134.86 2331.56 5678.02 7070.03 2032.03 NonCurLiab
DTL_Net 1555.06 1470.29 1700.80 1343.15 1408.17 NonCurLiab
Other_LTB 1678.92 1374.15 1057.54 585.11 698.22 NonCurLiab
# Filtering Current Assets from the mahindra_bs_long
current_assets_mahindra <- mahindra_bs_long[mahindra_bs_long$Items %in% c("CurInvst", "Inv", "TR", "Cash_CE", "OCurrAst","ST_LoanAdv"), ]

# Filtering Current Liabilities from the mahindra_bs_long
current_liabilities_mahindra <- mahindra_bs_long[mahindra_bs_long$Items %in% c("STBor", "TP", "OCurrLiab", "STProv"), ]

# Sum Current Assets and Current Liabilities for each year 2024 to 2020
current_assets_mahindra_sum <- colSums(current_assets_mahindra[, 2:6]) 
current_liabilities_mahindra_sum <- colSums(current_liabilities_mahindra[,2:6])  

# Calculate Current Ratio
current_ratio_mahindra <- current_assets_mahindra_sum / current_liabilities_mahindra_sum

# Displaying the Current Ratio
current_ratio_mahindra
##     2024     2023     2022     2021     2020 
## 1.351328 1.330401 1.377115 1.342237 1.379909
# Create a data frame for plotting
current_ratio_mahindra_data <- data.frame(
  Year = as.numeric(names(current_ratio_mahindra)),  # Extract year names
  current_ratio_mahindra = as.numeric(current_ratio_mahindra) # Convert ratios to numeric
)

# Plot = Current Ratio
ggplot(current_ratio_mahindra_data, aes(x = Year, y = current_ratio_mahindra)) +
  geom_line(color = "gold", linewidth = 1.5) +  # Use linewidth for line thickness
  geom_point(color = "purple", size = 3.5) +        # Add points for each year
  labs(
    title = "Current Ratio Trend for Mahindra & Mahindra (2020–2024)",
    x = "Year",
    y = "Current Ratio"
  ) +
  scale_y_continuous(
    limits = c(1.32, 1.39), # Set y-axis limits
    breaks = seq(1.32, 1.39, by = 0.01), # Set the breaks on the y-axis
    labels = scales::label_number(accuracy = 0.01), # Label the y-axis with values from 1.32 to 1.39
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load required libraries
library(ggplot2)

# Create bar plot
ggplot(current_ratio_mahindra_data, aes(x = factor(Year), 
                                        y = current_ratio_mahindra, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(title = "Current Ratio from (2020 - 2024)", x = "Year",
       y = "Current Ratio") +
  scale_fill_manual(values = c("2024" = "hotpink", "2023" = "orange",
                               "2022" = "red", "2021" = "grey", "2020" = "purple")) +
  geom_text(aes(label = round(current_ratio_mahindra, 2)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(0, 1.5), # Set y-axis limits
    breaks = seq(0, 1.5, by = 0.25), # Set the breaks on the y-axis
    labels = scales::label_number(accuracy = 0.01), # Label the y-axis with values from 0 to 1.5
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Load ggplot2 library
library(ggplot2)

# Create Df for Current Ratios
current_ratio_data <- data.frame(
  Year = rep(c(2020, 2021, 2022, 2023, 2024), 2),
  Company = c(rep("Tata Motors", 5), rep("Mahindra & Mahindra", 5)),
  Current_Ratio = c(0.5257, 0.6039, 0.5787, 0.4457, 0.5565,
                    1.3799, 1.3422, 1.3771, 1.3304, 1.3513)
)

# Bar Chart
ggplot(current_ratio_data, aes(x = factor(Year), y = Current_Ratio, fill = Company)) +
  geom_bar(stat = "identity", position = "dodge", color = "black", linewidth = 1) +
  labs(title = "Current Ratio Comparison: Tata Motors vs Mahindra & Mahindra", 
       subtitle = "(2020-2024)",
       x = "Year", 
       y = "Current Ratio",
       caption = "Source: Financial Reports of Tata Motors & Mahindra & Mahindra") +
  scale_fill_manual(values = c("Tata Motors" = "steelblue", 
                               "Mahindra & Mahindra" = "darkorange")) +
  geom_text(aes(label = round(Current_Ratio, 2)), 
            position = position_dodge(width = 0.9), 
            vjust = -0.3, size = 5, color = "black", fontface = "bold") +  
  scale_y_continuous(
    limits = c(0, 1.5),  
    breaks = seq(0, 1.5, by = 0.2)  
  ) + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 18, color = "black"),
    plot.subtitle = element_text(hjust = 0.5, size = 14, color = "gray40"),
    axis.title = element_text(size = 14, face = "bold"),
    axis.text = element_text(size = 12),
    legend.position = "top",
    legend.title = element_blank(),
    legend.text = element_text(size = 12, face = "bold"),
    panel.border = element_rect(color = "black", fill = NA, linewidth = 1.5)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

Conclusion:

Tata Motors has a low current ratio, indicating possible liquidity challenges and reliance on external funding. In contrast, Mahindra & Mahindra maintains a healthy current ratio, suggesting better financial stability and ability to meet short-term obligations.

LIQUIDITY

TATA MOTORS QUICK RATIO

BY RAHUL

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Quick Ratio
#Quick Ratio = Quick Asset/Current Liability
#First Step --> Quick Asset

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
qr1_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Cash_CE",])

qrp1_tata=ggplot(qr1_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Cash & Cash Equivalents",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1200, 5400),  # Set y-axis limits
    breaks = seq(1200, 5400, by = 600),  # Set the breaks on the y-axis
    labels = seq(12, 54, by = 6), # Label the y-axis with values from 12 to 54
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
qr2_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="CurInvst",])

qrp2_tata=ggplot(qr1_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Current Investments",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(600, 5400),  # Set y-axis limits
    breaks = seq(600, 5400, by = 600),  # Set the breaks on the y-axis
    labels = seq(6, 54, by = 6), # Label the y-axis with values from 6 to 54
  ) + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )
#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team3
qr3_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="ST_LoanAdv",])

qrp3_tata=ggplot(qr3_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Short-Term Loans & Advances",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(120, 240),  # Set y-axis limits
    breaks = seq(120, 240, by = 20),  # Set the breaks on the y-axis
    labels = seq(120, 240, by = 20),# Label the y-axis with values from 120 to 240
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )  

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
qr4_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="TR",])

qrp4_tata=ggplot(qr4_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Trade Receivables",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1700, 2900),  # Set y-axis limits
    breaks = seq(1700, 2900, by = 200),  # Set the breaks on the y-axis
    labels = seq(17, 29, by = 2),# Label the y-axis with values from 17 to 29
  )  +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Quick Assets

grid.arrange(qrp1_tata,qrp2_tata,qrp3_tata,qrp4_tata,nrow=2,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Quick Ratio = Quick Asset/current Liability
#Second Step --> Current Liability

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL
#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 5
qr5_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="OCurrLiab",])

qrp5_tata=ggplot(qr5_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Other Current Liability",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(8000, 12000),  # Set y-axis limits
    breaks = seq(8000, 12000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(8, 12, by = 1),# Label the y-axis with values from 8 to 12
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 6
qr6_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="STBor",])

qrp6_tata=ggplot(qr6_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Short-Term Borrowings",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(4000, 10000),  # Set y-axis limits
    breaks = seq(4000, 10000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(4, 10, by = 1),# Label the y-axis with values from 4 to 10
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 7
qr7_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="STProv",])

qrp7_tata=ggplot(qr7_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Short-Term Provisions",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(200, 1600),  # Set y-axis limits
    breaks = seq(200, 1600, by = 200),  # Set the breaks on the y-axis
    labels = seq(2, 16, by = 2), # Label the y-axis with values from 2 to 16
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 8
qr8_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="TP",])

qrp8_tata=ggplot(qr8_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Trade Payables",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(5500, 9500),  # Set y-axis limits
    breaks = seq(5500, 9500, by = 500),  # Set the breaks on the y-axis
    labels = seq(55, 95, by = 5), # Label the y-axis with values from 55 to 95
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Current Liability

grid.arrange(qrp5_tata,qrp6_tata,qrp7_tata,qrp8_tata,nrow=2,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

tata_bs_long<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
# Inspect the data structure
head(tata_bs_long)
Items 2024 2023 2022 2021 2020 Category
EqShCap 766.50 766.02 765.88 765.81 719.54 SholderFunds
Res_Surp 29374.83 21701.37 19171.88 18290.16 16800.61 SholderFunds
EqShApMony 1.72 2.46 6.39 0.00 0.00 SholderFunds
LTBor 5235.67 10445.70 14102.74 16326.77 14776.51 NonCurLiab
DTL_Net 49.78 51.16 173.72 266.50 198.59 NonCurLiab
Other_LTB 1392.16 1411.78 1212.34 1786.93 1646.56 NonCurLiab
# Filtering Quick Assets from the tata_bs_long
quick_assets <- tata_bs_long[tata_bs_long$Items %in% c("CurInvst", "TR", "Cash_CE","ST_LoanAdv"), ]

# Filtering Current Liabilities from the tata_bs_long
current_liabilities <- tata_bs_long[tata_bs_long$Items %in% c("STBor", "TP", "OCurrLiab", "STProv"), ]

# Sum Quick Assets and Current Liabilities for each year 2024 to 2020
quick_assets_sum <- colSums(quick_assets[, 2:6]) 
current_liabilities_sum <- colSums(current_liabilities[,2:6])  

# Calculate quick ratio
quick_ratio <- quick_assets_sum / current_liabilities_sum

# Displaying the quick ratio
quick_ratio
##      2024      2023      2022      2021      2020 
## 0.3674797 0.2711885 0.3704564 0.3111892 0.2567799
#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Create a data frame for plotting
quick_ratio_data <- data.frame(
  Year = as.numeric(names(quick_ratio)),  # Extract year names
  quick_ratio = as.numeric(quick_ratio) # Convert ratios to numeric
)

# Plot Quick Ratio Trend
ggplot(quick_ratio_data, aes(x = Year, y = quick_ratio)) +
  geom_line(color = "yellow", linewidth = 1.5) +  # Line thickness
  geom_point(color = "brown", size = 3.5) +      # Points on each year
  labs(
    title = "Quick Ratio Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Quick Ratio"
  ) +
  scale_y_continuous(
    limits = c(0.23, 0.38), # Set y-axis limits
    breaks = seq(0.23, 0.38, by = 0.05), # Set the breaks on the y-axis
    labels = scales::label_number(accuracy = 0.01), # Label the y-axis with values from 0.23 to 0.38
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Bar Plot for Quick Ratio
ggplot(quick_ratio_data, aes(x = factor(Year), y = quick_ratio, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(
    title = "Quick Ratio Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Quick Ratio"
  ) +
  scale_fill_manual(values = c("2024" = "red", "2023" = "blue",
                               "2022" = "orange", "2021" = "green", "2020" = "purple")) +
  geom_text(aes(label = round(quick_ratio, 3)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(0, 0.40),                           # Adjusted y-axis limits for Quick Ratio
    breaks = seq(0, 0.40, by = 0.05),              # Set breaks on y-axis
    labels = scales::label_number(accuracy = 0.001)   # Format labels to 3 decimal places
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

LIQUIDITY

MAHINDRA AND MAHINDRA LTD QUICK RATIO

BY RAHUL

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
mahindra_bs<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
mahindra_bs<-as.data.frame(mahindra_bs)

#clean the column names
colnames(mahindra_bs)<-make.names(colnames(mahindra_bs))
colnames(mahindra_bs)<-trimws(colnames(mahindra_bs))

#reshaping the data to long format
mahindra_bs_long<-reshape(mahindra_bs,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(mahindra_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Quick Ratio
#Quick Ratio = Quick Assets/Current Liability
#First Step --> Quick Assets

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
qr1_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="Cash_CE",])

qrp1_mahindra=ggplot(qr1_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="green",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="red",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Cash & Cash Equivalents",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(3400, 6400),  # Set y-axis limits
    breaks = seq(3400, 6400, by = 500),  # Set the breaks on the y-axis
    labels = seq(34, 64, by = 5), # Label the y-axis with values from 34 to 64
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
qr2_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="CurInvst",])

qrp2_mahindra=ggplot(qr2_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="green",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="red",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Current Investments",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1500, 10500),  # Set y-axis limits
    breaks = seq(1500, 10500, by = 1500),  # Set the breaks on the y-axis
    labels = seq(15, 105, by = 15), # Label the y-axis with values from 15 to 105
  ) + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
qr3_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="ST_LoanAdv",])

qrp3_mahindra=ggplot(qr3_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="green",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="red",
            linewidth=2)+
  labs(x="Year",y="Amount in 0's(cr.)",
       title="Short-Term Loans & Advances",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(400, 2500),  # Set y-axis limits
    breaks = seq(400, 2500, by = 350),  # Set the breaks on the y-axis
    labels = seq(40, 250, by = 35),# Label the y-axis with values from 40 to 250
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )  

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4

qr4_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="TR",])

qrp4_mahindra=ggplot(qr4_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="green",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="red",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Trade Receivables",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(2000, 4800),  # Set y-axis limits
    breaks = seq(2000, 4800, by = 400),  # Set the breaks on the y-axis
    labels = seq(20, 48, by = 4),# Label the y-axis with values from 20 to 48
  )  +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )  

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Quick Assets

grid.arrange(qrp1_mahindra,qrp2_mahindra,qrp3_mahindra,qrp4_mahindra,nrow=2,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Quick Ratio = Quick assets/Current Liability
#Second Step --> Current Liability

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
mahindra_bs<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
mahindra_bs<-as.data.frame(mahindra_bs)

#clean the column names
colnames(mahindra_bs)<-make.names(colnames(mahindra_bs))
colnames(mahindra_bs)<-trimws(colnames(mahindra_bs))

#reshaping the data to long format
mahindra_bs_long<-reshape(mahindra_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(mahindra_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 5
qr5_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="OCurrLiab",])

qrp5_mahindra=ggplot(qr5_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="green",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="red",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Other Current Liability",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(2400, 6400),  # Set y-axis limits
    breaks = seq(2400, 6400, by = 800),  # Set the breaks on the y-axis
    labels = seq(24, 64, by = 8),# Label the y-axis with values from 24 to 64
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 6
qr6_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="STBor",])

qrp6_mahindra=ggplot(qr6_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="green",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="red",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Short-Term Borrowings",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(0, 2500),  # Set y-axis limits
    breaks = seq(0, 2500, by = 500),  # Set the breaks on the y-axis
    labels = seq(0, 2500, by = 500),# Label the y-axis with values from 0 to 2500
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 7
qr7_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="STProv",])

qrp7_mahindra=ggplot(qr7_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="green",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="red",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Short-Term Provisions",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(400, 750),  # Set y-axis limits
    breaks = seq(400, 750, by = 50),  # Set the breaks on the y-axis
    labels = seq(400, 750, by = 50), # Label the y-axis with values from 400 to 750
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 8
qr8_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="TP",])

qrp8_mahindra=ggplot(qr8_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="green",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="red",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Trade Payables",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(5000, 20000),  # Set y-axis limits
    breaks = seq(5000, 20000, by = 5000),  # Set the breaks on the y-axis
    labels = seq(5, 20, by = 5), # Label the y-axis with values from 5 to 20
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Current Liability

grid.arrange(qrp5_mahindra,qrp6_mahindra,qrp7_mahindra,qrp8_mahindra,nrow=2,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------
#combined plot

#Balanced Layout - quick assests

grid.arrange(qrp1_mahindra,qrp2_mahindra,qrp3_mahindra,qrp4_mahindra,nrow=2,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

mahindra_bs_long<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
# Inspect the data structure
head(mahindra_bs_long)
Items 2024 2023 2022 2021 2020 Category
EqShCap 599.62 599.05 598.30 597.39 596.52 SholderFunds
Res_Surp 51378.18 42497.35 38139.19 33649.65 33606.36 SholderFunds
EqShApMony 298.76 260.33 223.46 254.88 264.96 SholderFunds
LTBor 1134.86 2331.56 5678.02 7070.03 2032.03 NonCurLiab
DTL_Net 1555.06 1470.29 1700.80 1343.15 1408.17 NonCurLiab
Other_LTB 1678.92 1374.15 1057.54 585.11 698.22 NonCurLiab
# Filtering Quick Assets from the mahindra_bs_long
quick_assets_mahindra <- mahindra_bs_long[mahindra_bs_long$Items %in% c("CurInvst", "TR", "Cash_CE","ST_LoanAdv"), ]

# Filtering Current Liabilities from the mahindra_bs_long
current_liabilities_mahindra <- mahindra_bs_long[mahindra_bs_long$Items %in% c("STBor", "TP", "OCurrLiab", "STProv"), ]

# Sum Quick Assets and Current Liabilities for each year 2024 to 2020
quick_assets_mahindra_sum <- colSums(quick_assets_mahindra[, 2:6]) 
current_liabilities_mahindra_sum <- colSums(current_liabilities_mahindra[,2:6])  

# Calculate Quick Ratio
quick_ratio_mahindra <- quick_assets_mahindra_sum / current_liabilities_mahindra_sum

# Displaying the quick ratio
quick_ratio_mahindra
##      2024      2023      2022      2021      2020 
## 0.8045406 0.7775905 0.8731651 0.9147905 0.9056159
# Create a data frame for plotting
quick_ratio_mahindra_data <- data.frame(
  Year = as.numeric(names(quick_ratio_mahindra)),  # Extract year names
  quick_ratio_mahindra = as.numeric(quick_ratio_mahindra) # Convert ratios to numeric
)

# Plot Quick Ratio Trend
ggplot(quick_ratio_mahindra_data, aes(x = Year, y = quick_ratio_mahindra)) +
  geom_line(color = "yellow", linewidth = 1.5) +  # Line thickness
  geom_point(color = "brown", size = 3.5) +      # Points on each year
  labs(
    title = "Quick Ratio Trend for Mahindra & Mahindra (2020–2024)",
    x = "Year",
    y = "Quick Ratio"
  ) +
  scale_y_continuous(
    limits = c(0.75, 0.95), # Set y-axis limits
    breaks = seq(0.75, 0.95, by = 0.04), # Set the breaks on the y-axis
    labels = scales::label_number(accuracy = 0.01), # Label the y-axis with values from 0.75 to 0.95
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Bar Plot for Quick Ratio (Mahindra & Mahindra)
ggplot(quick_ratio_mahindra_data, aes(x = factor(Year), y = quick_ratio_mahindra, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(
    title = "Quick Ratio Trend for Mahindra & Mahindra (2020–2024)",
    x = "Year",
    y = "Quick Ratio"
  ) +
  scale_fill_manual(values = c("2024" = "red", "2023" = "blue",
                               "2022" = "orange", "2021" = "green", "2020" = "purple")) +
  geom_text(aes(label = round(quick_ratio_mahindra, 3)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(0, 1),                # Adjusted y-axis limits for better visualization
    breaks = seq(0, 1, by = 0.10),    # Set breaks on y-axis
    labels = scales::label_number(accuracy = 0.001) # Format labels to 3 decimal places
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Load ggplot2 library
library(ggplot2)

# Create DF for Quick Ratios
quick_ratio_data <- data.frame(
  Year = rep(c(2020, 2021, 2022, 2023, 2024), 2),
  Company = c(rep("Tata Motors", 5), rep("Mahindra & Mahindra", 5)),
  Quick_Ratio = c(0.2568, 0.3112, 0.3705, 0.2712, 0.3675,  
                  0.9056, 0.9148, 0.8732, 0.7776, 0.8045)  
)

# Bar Chart
ggplot(quick_ratio_data, aes(x = factor(Year), y = Quick_Ratio, fill = Company)) +
  geom_bar(stat = "identity", position = "dodge", color = "black", linewidth = 1) +
  labs(title = "Quick Ratio Comparison: Tata Motors vs Mahindra & Mahindra", 
       subtitle = "(2020-2024)",
       x = "Year", 
       y = "Quick Ratio",
       caption = "Source: Financial Reports of Tata Motors & Mahindra & Mahindra") +
  scale_fill_manual(values = c("Tata Motors" = "royalblue", 
                               "Mahindra & Mahindra" = "tomato")) +
  geom_text(aes(label = round(Quick_Ratio, 2)), 
            position = position_dodge(width = 0.9), 
            vjust = -0.3, size = 5, color = "black", fontface = "bold") +  
  scale_y_continuous(
    limits = c(0, 1),  
    breaks = seq(0, 1, by = 0.2)  
  ) + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 18, color = "black"),
    plot.subtitle = element_text(hjust = 0.5, size = 14, color = "gray40"),
    axis.title = element_text(size = 14, face = "bold"),
    axis.text = element_text(size = 12),
    legend.position = "top",
    legend.title = element_blank(),
    legend.text = element_text(size = 12, face = "bold"),
    panel.border = element_rect(color = "black", fill = NA, linewidth = 1.5)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

Conclusion:

Tata Motors has a low quick ratio, indicating potential liquidity issues and difficulty covering short-term liabilities without selling inventory. Mahindra & Mahindra, with a stronger quick ratio, shows better short-term financial health and liquidity.

PROFITABILITY

TATA MOTORS NET PROFIT MARGIN RATIO

BY GOUTHAM S

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
tata_pl<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
tata_pl<-as.data.frame(tata_pl)

#clean the column names
colnames(tata_pl)<-make.names(colnames(tata_pl))
colnames(tata_pl)<-trimws(colnames(tata_pl))

#reshaping the data to long format
tata_pl_long<-reshape(tata_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Net Profit Margin
#Net Profit Margin = [(Net Profit/Loss) / Revenue] * 100
#First Step --> Net Profit/Loss

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
npm1_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="Net_PorL",])

npmp1_tata=ggplot(npm1_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkcyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Net Profit or Loss for the Period",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(min(npm1_tata$Amount, na.rm = TRUE), max(npm1_tata$Amount, na.rm = TRUE)),
    breaks = seq(-7500, 8500, by = 2000),  
    labels = seq(-75, 85, by = 20)
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Net Profit Margin = [(Net Profit/Loss) / Revenue] * 100
#Second Revenue

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
tata_pl<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
tata_pl<-as.data.frame(tata_pl)

#clean the column names
colnames(tata_pl)<-make.names(colnames(tata_pl))
colnames(tata_pl)<-trimws(colnames(tata_pl))

#reshaping the data to long format
tata_pl_long<-reshape(tata_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
npm2_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="Revenue_Op",])

npmp2_tata=ggplot(npm2_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkcyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Revenue From Operations",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(25000, 75000),  # Set y-axis limits
    breaks = seq(25000, 75000, by = 10000),  # Set the breaks on the y-axis
    labels = seq(25, 75, by = 10),# Label the y-axis with values from 25 to 75
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
npm3_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="OtherOpRev",])

npmp3_tata=ggplot(npm3_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkcyan",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Other Operating Revenue",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(350, 600),  # Set y-axis limits
    breaks = seq(350, 600, by = 50),  # Set the breaks on the y-axis
    labels = seq(350, 600, by = 50),# Label the y-axis with values from 350 to 600
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
npm4_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="OtherInc",])

npmp4_tata=ggplot(npm4_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkcyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Other Income",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(300, 1500),  # Set y-axis limits
    breaks = seq(300, 1500, by = 200),  # Set the breaks on the y-axis
    labels = seq(3, 15, by = 2), # Label the y-axis with values from 3 to 15
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )   

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Total Revenue

grid.arrange(
  npmp4_tata, npmp3_tata,  # First row: Two charts
  npmp2_tata,            # Second row: One wide chart
  nrow = 2,            # 2 rows
  ncol = 2,            # 2 columns
  layout_matrix = rbind(c(1, 2),  # Top two plots
                        c(3, 3)), # Bottom plot spans full width
  heights = c(1.5, 1.75)  # Give more space to bottom chart
)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Filtering Net Profit/Loss from tata_pl_long
net_profit_loss <- npm1_tata
#reset row names
row.names(net_profit_loss)<-NULL

#Filtering Revenure from the tata_pl_long
revenue <- tata_pl_long[tata_pl_long$Items %in% c("Revenue_Op", "OtherOpRev", "OtherInc"), ]

#Sum Revenue and Net Profit/Loss for each year 2024 to 2020
revenue_total <- aggregate(Amount ~ Year, revenue, sum)
net_profit_loss_total <- aggregate(Amount ~ Year, net_profit_loss, sum)

print(net_profit_loss_total)
##   Year   Amount
## 1 2020 -7289.63
## 2 2021 -2395.44
## 3 2022 -1390.86
## 4 2023  2728.13
## 5 2024  7902.08
print(revenue_total)
##   Year   Amount
## 1 2020 45311.22
## 2 2021 30595.02
## 3 2022 47923.59
## 4 2023 66578.27
## 5 2024 74452.96
#Calculate Net Profit Margin
#Convert Year to numeric
#Ensure Amount to numeric
net_profit_loss_total$Amount <- as.numeric(net_profit_loss_total$Amount)
revenue_total$Amount <- as.numeric(revenue_total$Amount)

#Compute Net Profit Ratio for each year
net_profit_margin <- (net_profit_loss_total$Amount / revenue_total$Amount) * 100

print(net_profit_margin)
## [1] -16.087914  -7.829510  -2.902245   4.097628  10.613520
#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Create the data frame for plotting
net_profit_margin_data <- data.frame(
  Year = as.numeric(net_profit_loss_total$Year),  # Extract Year from net_profit_loss_total
  net_profit_margin = net_profit_margin  # Use the computed vector directly
)

  #Plot Net Profit Margin Ratio
ggplot(net_profit_margin_data, aes(x = Year, y = net_profit_margin)) +
  geom_line(color = "hotpink", linewidth = 1.5) +  
  geom_point(color = "blue", size = 3.5) +       
  labs(
    title = "Net Profit Margin for Tata Motors (2020–2024)",
    x = "Year",
    y = "Net Profit Margin"
  ) +
  scale_y_continuous(
    limits = c(-18, 12), # Set y-axis limits
    breaks = seq(-18, 12, by = 2), # Set the breaks on the y-axis
    labels = seq(-18, 12, by = 2),  # Label the y-axis with values from -18 to 12 
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#-----------------------------------------------------------------------------------------------------------------------------------------------------
#Load ggplot2 library
library(ggplot2)

#Bar plot for Net Profit Margin
ggplot(net_profit_margin_data, aes(x = factor(Year), 
                                   y = net_profit_margin, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(title = "Net Profit Margin (2020 - 2024)", x = "Year",
       y = "Net Profit Margin (%)") +
  scale_fill_manual(values = c("2024" = "hotpink", "2023" = "green",
                               "2022" = "grey", "2021" = "blue", "2020" = "red")) +
  geom_text(aes(label = round(net_profit_margin, 2)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(-18, 12), # Set y-axis limits
    breaks = seq(-18, 12, by = 2), # Set breaks on y-axis
    labels = seq(-18, 12, by = 2),  # Label the y-axis with values from -18 to 12 
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

PROFITABILITY

MAHINDRA & MAHINDRA LTD NET PROFIT MARGIN RATIO

BY GOUTHAM S

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
mahindra_pl<-read_excel("E:/finalproject/Mahindra_PL_recleaned.xlsx")
mahindra_pl<-as.data.frame(mahindra_pl)

#clean the column names
colnames(mahindra_pl)<-make.names(colnames(mahindra_pl))
colnames(mahindra_pl)<-trimws(colnames(mahindra_pl))

#reshaping the data to long format
mahindra_pl_long<-reshape(mahindra_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(mahindra_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Net Profit Margin
#Net Profit Margin = [(Net Profit/Loss) / Revenue] * 100
#First Step --> Net Profit/Loss

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
npm1_mahindra=as.data.frame(mahindra_pl_long[mahindra_pl_long$Items=="Net_PorL",])

npmp1_mahindra=ggplot(npm1_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="black",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="red",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Net Profit or Loss for the Period",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(min(npm1_mahindra$Amount, na.rm = TRUE), max(npm1_mahindra$Amount, na.rm = TRUE)),
    breaks = seq(0, 11000, by = 1000),  
    labels = seq(0, 110, by = 10)
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Net Profit Margin = [(Net Profit/Loss) / Revenue] * 100
#Second Revenue

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
mahindra_pl<-read_excel("E:/finalproject/Mahindra_PL_recleaned.xlsx")
mahindra_pl<-as.data.frame(mahindra_pl)

#clean the column names
colnames(mahindra_pl)<-make.names(colnames(mahindra_pl))
colnames(mahindra_pl)<-trimws(colnames(mahindra_pl))

#reshaping the data to long format
mahindra_pl_long<-reshape(mahindra_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(mahindra_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
npm2_mahindra=as.data.frame(mahindra_pl_long[mahindra_pl_long$Items=="Revenue_Op",])

npmp2_mahindra=ggplot(npm2_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="black",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="red",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Revenue From Operations",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(40000, 100000),  # Set y-axis limits
    breaks = seq(40000, 100000, by = 10000),  # Set the breaks on the y-axis
    labels = seq(40, 100, by = 10),# Label the y-axis with values from 40 to 100
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
npm3_mahindra=as.data.frame(mahindra_pl_long[mahindra_pl_long$Items=="OtherOpRev",])

npmp3_mahindra=ggplot(npm3_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="black",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="red",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Other Operating Revenue",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(500, 2000),  # Set y-axis limits
    breaks = seq(500, 2000, by = 300),  # Set the breaks on the y-axis
    labels = seq(5, 20, by = 3),# Label the y-axis with values from 5 to 20
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
npm4_mahindra=as.data.frame(mahindra_pl_long[mahindra_pl_long$Items=="OtherInc",])

npmp4_mahindra=ggplot(npm4_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="black",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="red",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Other Income",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1000, 4300),  # Set y-axis limits
    breaks = seq(1000, 4300, by = 300),  # Set the breaks on the y-axis
    labels = seq(10, 43, by = 3), # Label the y-axis with values from 10 to 43
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )   

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Total Revenue

grid.arrange(
  npmp3_mahindra, npmp4_mahindra,  # First row: Two charts
  npmp2_mahindra,            # Second row: One wide chart
  nrow = 2,            # 2 rows
  ncol = 2,            # 2 columns
  layout_matrix = rbind(c(1, 2),  # Top two plots
                        c(3, 3)), # Bottom plot spans full width
  heights = c(1.75, 1.5)  # Give more space to top charts
)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Filtering Net Profit/Loss from mahindra_pl_long
net_profit_loss_mahindra <- npm1_mahindra
#reset row names
row.names(net_profit_loss_mahindra)<-NULL

#Filtering Revenure from the mahindra_pl_long
revenue_mahindra <- mahindra_pl_long[mahindra_pl_long$Items %in% c("Revenue_Op", "OtherOpRev", "OtherInc"), ]

#Sum Revenue and Net Profit/Loss for each year 2024 to 2020
revenue_mahindra_total <- aggregate(Amount ~ Year, revenue, sum)
net_profit_loss_mahindra_total <- aggregate(Amount ~ Year, net_profit_loss_mahindra, sum)

print(net_profit_loss_mahindra_total)
##   Year   Amount
## 1 2020  1330.55
## 2 2021   268.66
## 3 2022  4935.22
## 4 2023  6548.64
## 5 2024 10717.80
print(revenue_mahindra_total)
##   Year   Amount
## 1 2020 45311.22
## 2 2021 30595.02
## 3 2022 47923.59
## 4 2023 66578.27
## 5 2024 74452.96
#Calculate Net Profit Margin
#Convert Year to numeric
#Ensure Amount to numeric
net_profit_loss_mahindra_total$Amount <- as.numeric(net_profit_loss_mahindra_total$Amount)
revenue_mahindra_total$Amount <- as.numeric(revenue_mahindra_total$Amount)

#Compute Net Profit Ratio for each year
net_profit_margin_mahindra <- (net_profit_loss_mahindra_total$Amount / revenue_mahindra_total$Amount) * 100

print(net_profit_margin_mahindra)
## [1]  2.9364692  0.8781168 10.2981016  9.8360020 14.3953981
#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Create the data frame for plotting
net_profit_margin_mahindra_data <- data.frame(
  Year = as.numeric(net_profit_loss_mahindra_total$Year),  # Extract Year from net_profit_loss_mahindra_total
  net_profit_margin_mahindra = net_profit_margin_mahindra  # Use the computed vector directly
)

#Plot Net Profit Margin Ratio
ggplot(net_profit_margin_mahindra_data, aes(x = Year, y = net_profit_margin_mahindra)) +
  geom_line(color = "green", linewidth = 1.5) +  
  geom_point(color = "brown", size = 3.5) +       
  labs(
    title = "Net Profit Margin for Mahindra & Mahindra (2020–2024)",
    x = "Year",
    y = "Net Profit Margin(%)"
  ) +
  scale_y_continuous(
    limits = c(0, 15), # Set y-axis limits
    breaks = seq(0, 15, by = 1), # Set the breaks on the y-axis
    labels = seq(0, 15, by = 1),  # Label the y-axis with values from -18 to 12 
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Load ggplot2 library
library(ggplot2)

#Bar plot for Net Profit Margin
ggplot(net_profit_margin_mahindra_data, aes(x = factor(Year), 
                                            y = net_profit_margin_mahindra, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(title = "Net Profit Margin (2020 - 2024)", x = "Year",
       y = "Net Profit Margin (%)") +
  scale_fill_manual(values = c("2024" = "green", "2023" = "violet",
                               "2022" = "yellow", "2021" = "red", "2020" = "blue")) +
  geom_text(aes(label = round(net_profit_margin_mahindra, 2)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(-2, 16), # Set y-axis limits
    breaks = seq(-2, 16, by = 1), # Set breaks on y-axis
    labels = seq(-2, 16, by = 1),  # Label the y-axis with values from -2 to 16
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Load ggplot2 library
library(ggplot2)

# Create DF for Net Profit Margin
net_profit_margin_data <- data.frame(
  Year = rep(c(2020, 2021, 2022, 2023, 2024), 2),
  Company = c(rep("Tata Motors", 5), rep("Mahindra & Mahindra", 5)),
  Net_Profit_Margin = c(-16.09, -7.83, -2.90, 4.10, 10.61,  
                        2.94, 0.88, 10.30, 9.84, 14.40)  
)

# Bar Chart
ggplot(net_profit_margin_data, aes(x = factor(Year), y = Net_Profit_Margin, fill = Company)) +
  geom_bar(stat = "identity", position = "dodge", color = "black", linewidth = 1) +
  labs(title = "Net Profit Margin Comparison: Tata Motors vs Mahindra & Mahindra", 
       subtitle = "(2020-2024)",
       x = "Year", 
       y = "Net Profit Margin (%)",
       caption = "Source: Financial Reports of Tata Motors & Mahindra & Mahindra") +
  scale_fill_manual(values = c("Tata Motors" = "steelblue",  
                               "Mahindra & Mahindra" = "darkorange")) +  
  geom_text(aes(label = round(Net_Profit_Margin, 2)), 
            position = position_dodge(width = 0.9), 
            vjust = ifelse(net_profit_margin_data$Net_Profit_Margin < 0, 1.5, -0.5),  
            size = 5, color = "black", fontface = "bold") +  
  scale_y_continuous(
    limits = c(-20, 20),  
    breaks = seq(-20, 20, by = 5)  
  ) + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 18, color = "black"),
    plot.subtitle = element_text(hjust = 0.5, size = 14, color = "gray40"),
    axis.title = element_text(size = 14, face = "bold"),
    axis.text = element_text(size = 12),
    legend.position = "top",
    legend.title = element_blank(),
    legend.text = element_text(size = 12, face = "bold"),
    panel.border = element_rect(color = "black", fill = NA, linewidth = 1.5)
  )

#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Conclusion:

Tata Motors had negative net profit margins for three years, indicating losses, but showed improvement in 2023 and 2024. Mahindra & Mahindra maintained positive margins throughout, reflecting better profitability and financial stability.

ACTIVITY

TATA MOTORS ASSET TURNOVER RATIO

BY SHANKARANARAYANAN M

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
tata_pl<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
tata_pl<-as.data.frame(tata_pl)

#clean the column names
colnames(tata_pl)<-make.names(colnames(tata_pl))
colnames(tata_pl)<-trimws(colnames(tata_pl))

#reshaping the data to long format
tata_pl_long<-reshape(tata_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Fixed Asset Turnover Ratio
#Fixed Asset Turnover Ratio = Net Sales(Total Revenue)/Average Fixed Assets
#First step --> Net Sales(Total Revenue)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
fatr1_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="Revenue_Op",])

fatrp1_tata=ggplot(fatr1_tata,aes(x=Year,y=Amount))+
  geom_point(col="black",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkorange",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Revenue From Operations",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(25000, 75000),  # Set y-axis limits
    breaks = seq(25000, 75000, by = 10000),  # Set the breaks on the y-axis
    labels = seq(25, 75, by = 10),# Label the y-axis with values from 25 to 75
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
fatr2_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="OtherOpRev",])

fatrp2_tata=ggplot(fatr2_tata,aes(x=Year,y=Amount))+
  geom_point(col="black",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkorange",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Other Operating Revenue",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(350, 600),  # Set y-axis limits
    breaks = seq(350, 600, by = 50),  # Set the breaks on the y-axis
    labels = seq(350, 600, by = 50),# Label the y-axis with values from 350 to 600
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Net Sales(Total Revenue)

grid.arrange(
  fatrp1_tata,           #First row: One wide chart
  fatrp2_tata,           #Second row: One wide chart
  nrow = 2,            # 2 rows
  ncol = 1,            # 1 column
  heights = c(1.60, 1.75)  # Give more space to bottom chart
)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Fixed Asset Turnover Ratio = Net Sales(Total Revenue)/Average Fixed Assets

#Second step --> Finding Average Fixed Assets

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
tata_pl<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
tata_pl<-as.data.frame(tata_pl)

#clean the column names
colnames(tata_pl)<-make.names(colnames(tata_pl))
colnames(tata_pl)<-trimws(colnames(tata_pl))

#reshaping the data to long format
tata_pl_long<-reshape(tata_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3

fatr3_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="FA",])

fatrp3_tata=ggplot(fatr3_tata,aes(x=Year,y=Amount))+
  geom_point(col="black",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkorange",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Average Fixed Assets",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(12000, 32000),  # Set y-axis limits
    breaks = seq(12000, 32000, by = 2000),  # Set the breaks on the y-axis
    labels = seq(12, 32, by = 2), # Label the y-axis with values from 12 to 32
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Filtering Average Fixed Assets from the tata_bs_long
Avg_FixedAssets <- fatr3_tata
#reset row names
row.names(Avg_FixedAssets)<-NULL

#Filtering Net Sales(Total Revenue) from the tata_pl_long
Total_Revenue <- tata_pl_long[tata_pl_long$Items %in% c("Revenue_Op", "OtherOpRev"), ]

#Sum Average Fixed Assets and Net Sales(Total Revenue) for each year 2024 to 2020
Total_Revenue_total <- aggregate(Amount ~ Year, Total_Revenue, sum)
Avg_FixedAssets_total <- aggregate(Amount ~ Year, Avg_FixedAssets, sum)

print(Total_Revenue_total)
##   Year   Amount
## 1 2020 43928.17
## 2 2021 30175.03
## 3 2022 47263.68
## 4 2023 65757.33
## 5 2024 73303.08
print(Avg_FixedAssets_total)
##   Year   Amount
## 1 2020 29702.78
## 2 2021 29429.56
## 3 2022 15543.00
## 4 2023 15627.27
## 5 2024 15578.00
#Calculate Fixed Asset Turnover Ratio
#Convert Year to numeric
#Ensure Amount to numeric
Total_Revenue_total$Amount <- as.numeric(Total_Revenue_total$Amount)
Avg_FixedAssets_total$Amount <- as.numeric(Avg_FixedAssets_total$Amount)

# Calculate Fixed Asset Turnover Ratio
FixedAsset_TO_ratio <- Total_Revenue_total$Amount / Avg_FixedAssets_total$Amount

# Displaying the Fixexd Asset Turnover Ratio
FixedAsset_TO_ratio
## [1] 1.478925 1.025331 3.040834 4.207858 4.705551
#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Create the data frame for plotting
FixedAsset_TO_ratio_data <- data.frame(
  Year = as.numeric(Total_Revenue_total$Year),  # Extract Year from Total_Revenue_total
  FixedAsset_TO_ratio = FixedAsset_TO_ratio  # Use the computed vector directly
)

#Create line plot
ggplot(FixedAsset_TO_ratio_data, aes(x = Year, y = FixedAsset_TO_ratio)) +
  geom_line(color = "green", linewidth = 1.5) +  
  geom_point(color = "blue", size = 3.5) +       
  labs(
    title = "Fixed Asset Turnover Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Fixed Asset Turnover Ratio"
  ) +
  scale_y_continuous(
    limits = c(0, 5),              # Set y-axis limits
    breaks = seq(0, 5, by = 0.5),  # Set the breaks on the y-axis
    labels = seq(0, 5, by = 0.5),  # Label the y-axis with values from 3 to 5 
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Bar plot for Fixed Asset Turnover Ratio
ggplot(FixedAsset_TO_ratio_data, aes(x = factor(Year), 
                      y = FixedAsset_TO_ratio, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(title = "Fixed Asset Turnover Ratio (2020 - 2024)", 
       x = "Year",
       y = "Fixed Asset Turnover Ratio") +
  scale_fill_manual(values = c("2024" = "red", "2023" = "blue",
                               "2022" = "orange", "2021" = "green", "2020" = "purple")) +
  geom_text(aes(label = round(FixedAsset_TO_ratio, 2)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(0, 5),                              # Adjusted y-axis limits for FATO Ratio
    breaks = seq(0, 5, by = 1),                    # Set breaks on y-axis
    labels = scales::label_number(accuracy = 0.01) # Format labels
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

ACTIVITY

MAHINDRA & MAHINDRA LTD ASSET TURNOVER RATIO

BY SHANKARANARAYANAN M

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
mahindra_bs<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
mahindra_bs<-as.data.frame(mahindra_bs)

#clean the column names
colnames(mahindra_bs)<-make.names(colnames(mahindra_bs))
colnames(mahindra_bs)<-trimws(colnames(mahindra_bs))

#reshaping the data to long format
mahindra_bs_long<-reshape(mahindra_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(mahindra_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
mahindra_pl<-read_excel("E:/finalproject/Mahindra_PL_recleaned.xlsx")
mahindra_pl<-as.data.frame(mahindra_pl)

#clean the column names
colnames(mahindra_pl)<-make.names(colnames(mahindra_pl))
colnames(mahindra_pl)<-trimws(colnames(mahindra_pl))

#reshaping the data to long format
mahindra_pl_long<-reshape(mahindra_pl,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(mahindra_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Fixed Asset Turnover Ratio
#Fixed Asset Turnover Ratio = Net Sales(Total Revenue)/Average Fixed Assets
#First step --> Net Sales(Total Revenue)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
fatr1_mahindra=as.data.frame(mahindra_pl_long[mahindra_pl_long$Items=="Revenue_Op",])

fatrp1_mahindra=ggplot(fatr1_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="blue",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="green",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Revenue From Operations",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(40000, 100000),  # Set y-axis limits
    breaks = seq(40000, 100000, by = 5000),  # Set the breaks on the y-axis
    labels = seq(40, 100, by = 5),# Label the y-axis with values from 40 to 100
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
fatr2_mahindra=as.data.frame(mahindra_pl_long[mahindra_pl_long$Items=="OtherOpRev",])

fatrp2_mahindra=ggplot(fatr2_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="blue",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="green",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.",
       title="Other Operating Revenue",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(500, 1900),  # Set y-axis limits
    breaks = seq(500, 1900, by = 200),  # Set the breaks on the y-axis
    labels = seq(5, 20, by = 2),# Label the y-axis with values from 5 to 20
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Net Sales(Total Revenue)

grid.arrange(
  fatrp1_mahindra,           #First row: One wide chart
  fatrp2_mahindra,           #Second row: One wide chart
  nrow = 2,            # 2 rows
  ncol = 1,            # 1 column
  heights = c(2, 1.5)  # Give more space to top chart
)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Fixed Asset Turnover Ratio = Net Sales(Total Revenue)/Average Fixed Assets

#Second step --> Finding Average Fixed Assets

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
mahindra_bs<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
mahindra_bs<-as.data.frame(mahindra_bs)

#clean the column names
colnames(mahindra_bs)<-make.names(colnames(mahindra_bs))
colnames(mahindra_bs)<-trimws(colnames(mahindra_bs))

#reshaping the data to long format
mahindra_bs_long<-reshape(mahindra_bs,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(mahindra_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
mahindra_pl<-read_excel("E:/finalproject/Mahindra_PL_recleaned.xlsx")
mahindra_pl<-as.data.frame(mahindra_pl)

#clean the column names
colnames(mahindra_pl)<-make.names(colnames(mahindra_pl))
colnames(mahindra_pl)<-trimws(colnames(mahindra_pl))

#reshaping the data to long format
mahindra_pl_long<-reshape(mahindra_pl,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(mahindra_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3

fatr3_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="FA",])

fatrp3_mahindra=ggplot(fatr3_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="blue",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="green",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Average Fixed Assets",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(14000, 22000),  # Set y-axis limits
    breaks = seq(14000, 22000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(14, 22, by = 1), # Label the y-axis with values from 14 to 22
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Filtering Average Fixed Assets from the mahindra_bs_long
Avg_FixedAssets_mahindra <- fatr3_mahindra
#reset row names
row.names(Avg_FixedAssets_mahindra)<-NULL


#Filtering Net Sales(Total Revenue) from the mahindra_pl_long
Total_Revenue_mahindra <- mahindra_pl_long[mahindra_pl_long$Items %in% c("Revenue_Op", "OtherOpRev"), ]

#Sum Average Fixed Assets and Net Sales(Total Revenue) for each year 2024 to 2020
Total_Revenue_mahindra_total <- aggregate(Amount ~ Year, Total_Revenue_mahindra, sum)
Avg_FixedAssets_mahindra_total <- aggregate(Amount ~ Year, Avg_FixedAssets_mahindra, sum)

print(Total_Revenue_mahindra_total)
##   Year   Amount
## 1 2020 45487.78
## 2 2021 45040.98
## 3 2022 57445.97
## 4 2023 84960.26
## 5 2024 98763.42
print(Avg_FixedAssets_mahindra_total)
##   Year   Amount
## 1 2020 14404.05
## 2 2021 15011.51
## 3 2022 19566.79
## 4 2023 19760.82
## 5 2024 21283.83
#Calculate Fixed Asset Turnover Ratio
#Convert Year to numeric
#Ensure Amount to numeric
Total_Revenue_mahindra_total$Amount <- as.numeric(Total_Revenue_mahindra_total$Amount)
Avg_FixedAssets_mahindra_total$Amount <- as.numeric(Avg_FixedAssets_mahindra_total$Amount)

# Calculate Fixed Asset Turnover Ratio
FixedAsset_TO_ratio_mahindra <- Total_Revenue_mahindra_total$Amount / Avg_FixedAssets_mahindra_total$Amount

# Displaying the Fixexd Asset Turnover Ratio
FixedAsset_TO_ratio_mahindra
## [1] 3.157985 3.000430 2.935891 4.299430 4.640303
#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Create the data frame for plotting
FixedAsset_TO_ratio_mahindra_data <- data.frame(
  Year = as.numeric(Total_Revenue_mahindra_total$Year),  # Extract Year from Total_Revenue_mahindra_total
  FixedAsset_TO_ratio_mahindra = FixedAsset_TO_ratio_mahindra  # Use the computed vector directly
)

#Create line plot
ggplot(FixedAsset_TO_ratio_mahindra_data, aes(x = Year, y = FixedAsset_TO_ratio_mahindra)) +
  geom_line(color = "black", linewidth = 1.5) +  
  geom_point(color = "darkorange", size = 3.5) +       
  labs(
    title = "Fixed Asset Turnover Trend for Mahindra & Mahindra Limited (2020–2024)",
    x = "Year",
    y = "Fixed Asset Turnover Ratio"
  ) +
  scale_y_continuous(
    limits = c(2.5, 5),              # Set y-axis limits
    breaks = seq(2.5, 5, by = 0.5),  # Set the breaks on the y-axis
    labels = seq(2.5, 5, by = 0.5),  # Label the y-axis with values from 2.5 to 5 
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Bar plot for Fixed Asset Turnover Ratio
ggplot(FixedAsset_TO_ratio_mahindra_data, aes(x = factor(Year), 
                                     y = FixedAsset_TO_ratio_mahindra, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(title = "Fixed Asset Turnover Ratio (2020 - 2024)", 
       x = "Year",
       y = "Fixed Asset Turnover Ratio") +
  scale_fill_manual(values = c("2024" = "blue", "2023" = "red",
                               "2022" = "green", "2021" = "purple", "2020" = "orange")) +
  geom_text(aes(label = round(FixedAsset_TO_ratio_mahindra, 2)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(0, 5),                              # Adjusted y-axis limits for FATO Ratio
    breaks = seq(0, 5, by = 1),                    # Set breaks on y-axis
    labels = scales::label_number(accuracy = 0.01) # Format labels
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Load ggplot2 library
library(ggplot2)

# Create DF for Fixed Asset Turnover Ratio
fixed_asset_to_data <- data.frame(
  Year = rep(c(2020, 2021, 2022, 2023, 2024), 2),
  Company = c(rep("Tata Motors", 5), rep("Mahindra & Mahindra", 5)),
  Fixed_Asset_TO_Ratio = c(1.48, 1.03, 3.04, 4.21, 4.71,  
                           3.16, 3.00, 2.94, 4.30, 4.64)  
)

# Bar Chart
ggplot(fixed_asset_to_data, aes(x = factor(Year), y = Fixed_Asset_TO_Ratio, fill = Company)) +
  geom_bar(stat = "identity", position = "dodge", color = "black", linewidth = 1) +
  labs(title = "Fixed Asset Turnover Ratio: Tata Motors vs Mahindra & Mahindra", 
       subtitle = "(2020-2024)",
       x = "Year", 
       y = "Fixed Asset Turnover Ratio",
       caption = "Source: Financial Reports of Tata Motors & Mahindra & Mahindra") +
  scale_fill_manual(values = c("Tata Motors" = "steelblue",  
                               "Mahindra & Mahindra" = "darkorange")) +  
  geom_text(aes(label = round(Fixed_Asset_TO_Ratio, 2)), 
            position = position_dodge(width = 0.9), 
            vjust = -0.3,  
            size = 5, color = "black", fontface = "bold") +  
  scale_y_continuous(
    limits = c(0, 6),  
    breaks = seq(0, 6, by = 1)  
  ) + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 18, color = "black"),
    plot.subtitle = element_text(hjust = 0.5, size = 14, color = "gray40"),
    axis.title = element_text(size = 14, face = "bold"),
    axis.text = element_text(size = 12),
    legend.position = "top",
    legend.title = element_blank(),
    legend.text = element_text(size = 12, face = "bold"),
    panel.border = element_rect(color = "black", fill = NA, linewidth = 1.5)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

Conclusion:

Tata Motors showed significant improvement in fixed asset turnover over the years, indicating better asset utilization. Mahindra & Mahindra maintained a consistently strong ratio, suggesting efficient use of fixed assets for generating revenue.

ACTIVITY

TATA MOTORS INVENTORY TURNOVER RATIO

BY SHANKARANARAYANAN M

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)
#---------------------------------------------------------------------------------------------------
#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL
#---------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
tata_pl<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
tata_pl<-as.data.frame(tata_pl)

#clean the column names
colnames(tata_pl)<-make.names(colnames(tata_pl))
colnames(tata_pl)<-trimws(colnames(tata_pl))

#reshaping the data to long format
tata_pl_long<-reshape(tata_pl,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(tata_pl_long)<-NULL

#---------------------------------------------------------------------------------------------------

#Finding Inventory Turnover Ratio
#Inventory turnover ratio = Cost of Goods Sold / Average Inventory
#First COGS

#---------------------------------------------------------------------------------------------------

#team 1
itr1_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="COGS",])

itrp1_tata=ggplot(itr1_tata,aes(x=Year,y=Amount))+
  geom_point(col="purple",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="cyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Cost of Goods Sold",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(18000, 46000),              # Set y-axis limits
    breaks = seq(18000, 46000, by = 2000), # Set the breaks on the y-axis 
    labels = seq(18, 46, by = 2)           # Label the y-axis with values from 17 to 46
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#---------------------------------------------------------------------------------------------------

#Finding Inventory Turnover Ratio
#Inventory turnover ratio = Cost of Goods Sold / Average Inventory
#Second Step --> Average Inventory

#---------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#---------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
tata_pl<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
tata_pl<-as.data.frame(tata_pl)

#clean the column names
colnames(tata_pl)<-make.names(colnames(tata_pl))
colnames(tata_pl)<-trimws(colnames(tata_pl))

#reshaping the data to long format
tata_pl<-reshape(tata_pl,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(tata_pl_long)<-NULL

#---------------------------------------------------------------------------------------------------

#team 2
itr2_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Inv",])

itrp2_tata=ggplot(itr2_tata,aes(x=Year,y=Amount))+
  geom_point(col="purple",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="cyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Average Inventory",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(2700, 4700),  # Set y-axis limits
    breaks = seq(2700, 4700, by = 200),  # Set the breaks on the y-axis
    labels = seq(27, 47, by = 2),# Label the y-axis with values from 27 to 47
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#---------------------------------------------------------------------------------------------------

#Filtering COGS from the tata_pl_long
COGS <- itr1_tata
#reset row names
row.names(COGS)<-NULL

#Filtering Average Inventory from the tata_bs_long
AvgInv <- itr2_tata
#reset row names
row.names(AvgInv)<-NULL

print(COGS)
##   Items Category Year   Amount id
## 1  COGS Expenses 2024 45025.05  4
## 2  COGS Expenses 2023 42226.81  4
## 3  COGS Expenses 2022 31693.11  4
## 4  COGS Expenses 2021 19050.74  4
## 5  COGS Expenses 2020 26171.85  4
print(AvgInv)
##   Items Category Year  Amount id
## 1   Inv   CurAst 2024 3470.38 22
## 2   Inv   CurAst 2023 3027.90 22
## 3   Inv   CurAst 2022 3718.49 22
## 4   Inv   CurAst 2021 4551.71 22
## 5   Inv   CurAst 2020 3831.92 22
#Sum COGS and Average Inventory for each year 2024 to 2020
COGS_total <- aggregate(Amount ~ Year, COGS, sum)
AvgInv_total <- aggregate(Amount ~ Year, AvgInv, sum)

print(COGS_total)
##   Year   Amount
## 1 2020 26171.85
## 2 2021 19050.74
## 3 2022 31693.11
## 4 2023 42226.81
## 5 2024 45025.05
print(AvgInv_total)
##   Year  Amount
## 1 2020 3831.92
## 2 2021 4551.71
## 3 2022 3718.49
## 4 2023 3027.90
## 5 2024 3470.38
# Calculate Inventory Turnover Ratio
Inventory_TO_ratio <- COGS_total$Amount / AvgInv_total$Amount

# Displaying the Inventory Turnover Ratio
Inventory_TO_ratio
## [1]  6.829957  4.185403  8.523113 13.945906 12.974098
#---------------------------------------------------------------------------------------------------

# Create the data frame for plotting
Inventory_TO_ratio_data <- data.frame(
  Year = as.numeric(COGS_total$Year),  # Extract Year from COGS_total
  Inventory_TO_ratio = Inventory_TO_ratio  # Use the computed vector directly
)

#Create line plot
ggplot(Inventory_TO_ratio_data, aes(x = Year, y = Inventory_TO_ratio)) +
  geom_line(color = "red", linewidth = 1.5) +  
  geom_point(color = "blue", size = 3.5) +       
  labs(
    title = "Inventory Turnover Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Inventory Turnover Ratio"
  ) +
  scale_y_continuous(
    limits = c(3, 15),            # Set y-axis limits
    breaks = seq(3, 15, by = 1),  # Set the breaks on the y-axis
    labels = seq(3, 15, by = 1),  # Label the y-axis with values from 3 to 15 
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#---------------------------------------------------------------------------------------------------
# Bar Plot for Inventory Turnover Ratio
ggplot(Inventory_TO_ratio_data, aes(x = factor(Year), 
                                    y = Inventory_TO_ratio, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(title = "Inventory Turnover Ratio (2020 - 2024)", 
       x = "Year",
       y = "Inventory Turnover Ratio") +
  scale_fill_manual(values = c("2024" = "red", "2023" = "blue",
                               "2022" = "orange", "2021" = "green", "2020" = "purple")) +
  geom_text(aes(label = round(Inventory_TO_ratio, 2)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(0, 15),                              # Adjusted y-axis limits for Inventory TO Ratio
    breaks = seq(0, 15, by = 2),                    # Set breaks on y-axis
    labels = scales::label_number(accuracy = 0.01) # Format labels
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#---------------------------------------------------------------------------------------------------

ACTIVITY

MAHINDRA & MAHINDRA LTD INVENTORY TURNOVER RATIO

BY SHANKARANARAYANAN M

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#---------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
mahindra_bs<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
mahindra_bs<-as.data.frame(mahindra_bs)

#clean the column names
colnames(mahindra_bs)<-make.names(colnames(mahindra_bs))
colnames(mahindra_bs)<-trimws(colnames(mahindra_bs))

#reshaping the data to long format
mahindra_bs_long<-reshape(mahindra_bs,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(mahindra_bs_long)<-NULL

#---------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
mahindra_pl<-read_excel("E:/finalproject/Mahindra_PL_recleaned.xlsx")
mahindra_pl<-as.data.frame(mahindra_pl)

#clean the column names
colnames(mahindra_pl)<-make.names(colnames(mahindra_pl))
colnames(mahindra_pl)<-trimws(colnames(mahindra_pl))

#reshaping the data to long format
mahindra_pl_long<-reshape(mahindra_pl,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(mahindra_pl_long)<-NULL

#---------------------------------------------------------------------------------------------------

#Finding Inventory Turnover Ratio
#Inventory turnover ratio = Cost of Goods Sold / Average Inventory
#First COGS

#---------------------------------------------------------------------------------------------------

#team 1
itr1_mahindra=as.data.frame(mahindra_pl_long[mahindra_pl_long$Items=="COGS",])

itrp1_mahindra=ggplot(itr1_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="red",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="blue",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Cost Of Goods Sold",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(20000, 75000),              # Set y-axis limits
    breaks = seq(20000, 75000, by = 5000), # Set the breaks on the y-axis 
    labels = seq(20, 75, by = 5)           # Label the y-axis with values from 20 to 75
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#---------------------------------------------------------------------------------------------------

#Finding Inventory Turnover Ratio
#Inventory turnover ratio = Cost of Goods Sold / Average Inventory
#Second Step --> Average Inventory

#---------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
mahindra_bs<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
mahindra_bs<-as.data.frame(mahindra_bs)

#clean the column names
colnames(mahindra_bs)<-make.names(colnames(mahindra_bs))
colnames(mahindra_bs)<-trimws(colnames(mahindra_bs))

#reshaping the data to long format
mahindra_bs_long<-reshape(mahindra_bs,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(mahindra_bs_long)<-NULL

#---------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
mahindra_pl<-read_excel("E:/finalproject/Mahindra_PL_recleaned.xlsx")
mahindra_pl<-as.data.frame(mahindra_pl)

#clean the column names
colnames(mahindra_pl)<-make.names(colnames(mahindra_pl))
colnames(mahindra_pl)<-trimws(colnames(mahindra_pl))

#reshaping the data to long format
mahindra_pl_long<-reshape(mahindra_pl,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(mahindra_pl_long)<-NULL

#---------------------------------------------------------------------------------------------------

#team 2
itr2_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="Inv",])

itrp2_mahindra=ggplot(itr2_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="red",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="blue",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Average Inventory",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(3000, 10000),  # Set y-axis limits
    breaks = seq(3000, 10000, by = 500),  # Set the breaks on the y-axis
    labels = seq(30, 100, by = 5),# Label the y-axis with values from 30 to 100
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#---------------------------------------------------------------------------------------------------

#Filtering COGS from the mahindra_pl_long
COGS_mahindra <- itr1_mahindra
#reset row names
row.names(COGS_mahindra)<-NULL

#Filtering Average Inventory from the mahindra_bs_long
AvgInv_mahindra <- itr2_mahindra
#reset row names
row.names(AvgInv_mahindra)<-NULL

print(COGS_mahindra)
##   Items Category Year   Amount id
## 1  COGS Expenses 2024 71553.40  4
## 2  COGS Expenses 2023 62226.20  4
## 3  COGS Expenses 2022 40506.15  4
## 4  COGS Expenses 2021 25035.89  4
## 5  COGS Expenses 2020 22873.74  4
print(AvgInv_mahindra)
##   Items Category Year  Amount id
## 1   Inv   CurAst 2024 9504.82 21
## 2   Inv   CurAst 2023 8881.35 21
## 3   Inv   CurAst 2022 5882.85 21
## 4   Inv   CurAst 2021 3955.47 21
## 5   Inv   CurAst 2020 3400.91 21
#Sum COGS and Average Inventory for each year 2024 to 2020
COGS_mahindra_total <- aggregate(Amount ~ Year, COGS_mahindra, sum)
AvgInv_mahindra_total <- aggregate(Amount ~ Year, AvgInv_mahindra, sum)

print(COGS_mahindra_total)
##   Year   Amount
## 1 2020 22873.74
## 2 2021 25035.89
## 3 2022 40506.15
## 4 2023 62226.20
## 5 2024 71553.40
print(AvgInv_mahindra_total)
##   Year  Amount
## 1 2020 3400.91
## 2 2021 3955.47
## 3 2022 5882.85
## 4 2023 8881.35
## 5 2024 9504.82
# Calculate Inventory Turnover Ratio
Inventory_TO_ratio_mahindra <- COGS_mahindra_total$Amount / AvgInv_mahindra_total$Amount

# Print the result
print(Inventory_TO_ratio_mahindra)
## [1] 6.725770 6.329435 6.885464 7.006390 7.528117
#---------------------------------------------------------------------------------------------------

# Create the data frame for plotting
Inventory_TO_ratio_mahindra_data <- data.frame(
  Year = as.numeric(COGS_mahindra_total$Year),  # Extract Year from COGS_mahindra_total
  Inventory_TO_ratio_mahindra = Inventory_TO_ratio_mahindra  # Use the computed vector directly
)

#Create line plot
ggplot(Inventory_TO_ratio_mahindra_data, aes(x = Year, y = Inventory_TO_ratio_mahindra)) +
  geom_line(color = "purple", linewidth = 1.5) +  
  geom_point(color = "red", size = 3.5) +       
  labs(
    title = "Inventory Turnover Trend for Mahindra & Mahindra Limited (2020–2024)",
    x = "Year",
    y = "Inventory Turnover Ratio"
  ) +
  scale_y_continuous(
    limits = c(6, 7.75),               # Set y-axis limits
    breaks = seq(6, 7.75, by = 0.25),  # Set the breaks on the y-axis
    labels = seq(6, 7.75, by = 0.25)   # Label the y-axis with values from 6 to 7.75 
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#---------------------------------------------------------------------------------------------------
# Bar Plot for Inventory Turnover Ratio (Mahindra & Mahindra)
ggplot(Inventory_TO_ratio_mahindra_data, aes(x = factor(Year), y = Inventory_TO_ratio_mahindra, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(
    title = "Inventory Turnover Trend for Mahindra & Mahindra Limited (2020–2024)",
    x = "Year",
    y = "Inventory Turnover Ratio"
  ) +
  scale_fill_manual(values = c("2024" = "red", "2023" = "blue",
                               "2022" = "orange", "2021" = "green", "2020" = "purple")) +
  geom_text(aes(label = round(Inventory_TO_ratio_mahindra, 3)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(0, 8),                # Adjusted y-axis limits for better visualization
    breaks = seq(0, 8, by = 1),    # Set breaks on y-axis
    labels = scales::label_number(accuracy = 0.001) # Format labels to 3 decimal places
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#---------------------------------------------------------------------------------------------------
# Load ggplot2 library
library(ggplot2)

# Create DF for Inventory Turnover Ratio
inventory_to_data <- data.frame(
  Year = rep(c(2020, 2021, 2022, 2023, 2024), 2),
  Company = c(rep("Tata Motors", 5), rep("Mahindra & Mahindra", 5)),
  Inventory_TO_Ratio = c(6.83, 4.19, 8.52, 13.95, 12.97,  
                         6.73, 6.33, 6.89, 7.01, 7.53)  
)

# Bar Chart
ggplot(inventory_to_data, aes(x = factor(Year), y = Inventory_TO_Ratio, fill = Company)) +
  geom_bar(stat = "identity", position = "dodge", color = "black", linewidth = 1) +
  labs(title = "Inventory Turnover Ratio: Tata Motors vs Mahindra & Mahindra", 
       subtitle = "(2020-2024)",
       x = "Year", 
       y = "Inventory Turnover Ratio",
       caption = "Source: Financial Reports of Tata Motors & Mahindra & Mahindra") +
  scale_fill_manual(values = c("Tata Motors" = "steelblue",  
                               "Mahindra & Mahindra" = "darkorange")) +  
  geom_text(aes(label = round(Inventory_TO_Ratio, 2)), 
            position = position_dodge(width = 0.9), 
            vjust = -0.3,  
            size = 5, color = "black", fontface = "bold") +  
  scale_y_continuous(
    limits = c(0, 15),  
    breaks = seq(0, 15, by = 2)  
  ) + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 18, color = "black"),
    plot.subtitle = element_text(hjust = 0.5, size = 14, color = "gray40"),
    axis.title = element_text(size = 14, face = "bold"),
    axis.text = element_text(size = 12),
    legend.position = "top",
    legend.title = element_blank(),
    legend.text = element_text(size = 12, face = "bold"),
    panel.border = element_rect(color = "black", fill = NA, linewidth = 1.5)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

Conclusion:

Tata Motors shows fluctuations in inventory turnover, with a notable peak in 2023, indicating better inventory management that year. Mahindra & Mahindra maintains a steady and stable inventory turnover, reflecting consistent efficiency in handling inventory.

SOLVENCY

TATA MOTORS DEBT TO EQUITY RATIO

BY HAREESH R

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------



#Finding Debt-to-Equity Ratio
#Debt-to-Equity Ratio = Total Debt/Total Shareholders' Equity
#First step --> Finding Total Debt

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
d1_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="LTBor",])

dp1_tata=ggplot(d1_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkviolet",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="gold",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Long-Term Borrowings",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(4000, 18000),  # Set y-axis limits
    breaks = seq(4000, 18000, by = 2000),  # Set the breaks on the y-axis
    labels = seq(4, 18, by = 2), # Label the y-axis with values from 4 to 18
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Debt-to-Equity Ratio = Total Debt/Total Shareholders' Equity

#Second step --> Finding Total Shareholders' Equity

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
d2_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="EqShCap",])

dp2_tata=ggplot(d2_tata, aes(x = Year, y = Amount)) +
  geom_point(col = "darkviolet", size = 5) +
  geom_line(aes(group = 1), col = "gold", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in Crores",
    title = "Equity Share Capital",
    caption = "Cleaned by Team",
    subtitle = "TATA Motors Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(710, 780),            # Set y-axis limits
    breaks = seq(710, 780, by = 10), # Set the breaks on the y-axis
    labels = seq(710, 780, by = 10)     # Label the y-axis with values from 710 to 780
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
d3_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Res_Surp",])

dp3_tata=ggplot(d3_tata, aes(x = Year, y = Amount)) +
  geom_point(col = "darkviolet", size = 5) +
  geom_line(aes(group = 1), col = "gold", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in 000's(cr.)",
    title = "Reserves & Surplus",
    caption = "Cleaned by Team",
    subtitle = "TATA Motors Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(15000, 31000),            # Set y-axis limits
    breaks = seq(15000, 31000, by = 2000), # Set the breaks on the y-axis
    labels = seq(15, 31, by = 2)     # Label the y-axis with values from 15 to 31
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
d4_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="EqShApMony",])

dp4_tata=ggplot(d4_tata, aes(x = Year, y = Amount)) +
  geom_point(col = "darkviolet", size = 5) +
  geom_line(aes(group = 1), col = "gold", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in Crores",
    title = "Equity Share Application Money",
    caption = "Cleaned by Team",
    subtitle = "TATA Motors Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(0, 7),            # Set y-axis limits
    breaks = seq(0, 7, by = 1),  # Set the breaks on the y-axis
    labels = seq(0, 7, by = 1)   # Label the y-axis with values from 0 to 7
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )
   
#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Total Shareholders' Funds

grid.arrange(
  dp2_tata, dp4_tata,  # First row: Two charts
  dp3_tata,            # Second row: One wide chart
  nrow = 2,            # 2 rows
  ncol = 2,            # 2 columns
  layout_matrix = rbind(c(1, 2),  # Top two plots
                        c(3, 3)), # Bottom plot spans full width
  heights = c(1.5, 1.75)  # Give more space to bottom chart
)

#-----------------------------------------------------------------------------------------------------------------------------------------------------
#Debt-to-Equity Ratio = Total Debt/Total Shareholders' Equity

tata_bs_long<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
# Inspect the data structure
head(tata_bs_long)
Items 2024 2023 2022 2021 2020 Category
EqShCap 766.50 766.02 765.88 765.81 719.54 SholderFunds
Res_Surp 29374.83 21701.37 19171.88 18290.16 16800.61 SholderFunds
EqShApMony 1.72 2.46 6.39 0.00 0.00 SholderFunds
LTBor 5235.67 10445.70 14102.74 16326.77 14776.51 NonCurLiab
DTL_Net 49.78 51.16 173.72 266.50 198.59 NonCurLiab
Other_LTB 1392.16 1411.78 1212.34 1786.93 1646.56 NonCurLiab
# Filtering Total Debt from the tata_bs_long
total_debt <- tata_bs_long[tata_bs_long$Items %in% c("LTBor"), ]

# Filtering Total Shareholders' Funds from the tata_bs_long
total_shareholders_funds <- tata_bs_long[tata_bs_long$Items %in% c("EqShCap", "Res_Surp", "EqShApMony"), ]

# Sum Total Debts and Total Shareholders' Funds for each year 2024 to 2020
total_debt_sum <- colSums(total_debt[, 2:6]) 
total_shareholders_funds_sum <- colSums(total_shareholders_funds[,2:6])  

# Calculate Debt-to-Equity Ratio
debt_equity_ratio <- total_debt_sum / total_shareholders_funds_sum

# Displaying the Debt-to-Equity Ratio
debt_equity_ratio
##      2024      2023      2022      2021      2020 
## 0.1736941 0.4648763 0.7071116 0.8567798 0.8434009
#Create a data frame for plotting
debt_equity_ratio_data <- data.frame(
  Year = as.numeric(names(debt_equity_ratio)),  # Extract years from names
  debt_equity_ratio = as.numeric(debt_equity_ratio)  # Convert values to numeric
)
#-----------------------------------------------------------------------------------------------------------------------------------------------------
#line plot
#Plot Debt-to-Equity Ratio
  ggplot(debt_equity_ratio_data, aes(x = Year, y = debt_equity_ratio)) +
    geom_line(color = "cyan", linewidth = 1.5) +  # Use linewidth for line thickness
    geom_point(color = "red", size = 3.5) +     # Add points for each year
    labs(
      title = "Debt-to-Equity Trend for Tata Motors (2020–2024)",
      x = "Year",
      y = "Debt-to-Equity Ratio"
    ) +
    scale_y_continuous(
      limits = c(0, 1), # Set y-axis limits
      breaks = seq(0, 1, by = 0.1), # Set the breaks on the y-axis
      labels = seq(0, 1, by = 0.1)  # Label the y-axis with values from 0 to 1
    ) +
    theme_minimal() +
    theme(
      plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
      axis.title = element_text(size = 12),
      axis.text = element_text(size = 10)
    )

#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Bar Plot for Debt-to-Equity Ratio
ggplot(debt_equity_ratio_data, aes(x = factor(Year), y = debt_equity_ratio, fill = debt_equity_ratio)) +
  geom_bar(stat = "identity", color = "black", width = 0.6) +  # border
  geom_text(aes(label = round(debt_equity_ratio, 2)), vjust = -0.5, size = 5, fontface = "bold") +  
  labs(
    title = "Debt-to-Equity Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Debt-to-Equity Ratio"
  ) +
  scale_y_continuous(
    limits = c(0, 1), # Set y-axis limits
    breaks = seq(0, 1, by = 0.1), # Set the breaks on the y-axis
    labels = seq(0, 1, by = 0.1)  # Label the y-axis with values from 0 to 1
  ) +
  scale_fill_gradient(low = "skyblue", high = "darkblue") + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10),
    legend.position = "none"
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

SOLVENCY

MAHINDRA & MAHINDRA LTD DEBT TO EQUITY RATIO

BY HAREESH R

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
mahindra_bs<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
mahindra_bs<-as.data.frame(mahindra_bs)

#clean the column names
colnames(mahindra_bs)<-make.names(colnames(mahindra_bs))
colnames(mahindra_bs)<-trimws(colnames(mahindra_bs))

#reshaping the data to long format
mahindra_bs_long<-reshape(mahindra_bs,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(mahindra_bs_long)<-NULL

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



#Finding Debt-to-Equity Ratio
#Debt-to-Equity Ratio = Total Debt/Total Shareholders' Equity
#First step --> Finding Total Debt

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
d1_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="LTBor",])

dp1_mahindra=ggplot(d1_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="darkblue",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="pink",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Long-Term Borrowings",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(800, 7200),  # Set y-axis limits
    breaks = seq(800, 7200, by = 800),  # Set the breaks on the y-axis
    labels = seq(8, 72, by = 8), # Label the y-axis with values from 8 to 72
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Debt-to-Equity Ratio = Total Debt/Total Shareholders' Equity

#Second step --> Finding Total Shareholders' Equity

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
mahindra_bs<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
mahindra_bs<-as.data.frame(mahindra_bs)

#clean the column names
colnames(mahindra_bs)<-make.names(colnames(mahindra_bs))
colnames(mahindra_bs)<-trimws(colnames(mahindra_bs))

#reshaping the data to long format
mahindra_bs_long<-reshape(mahindra_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(mahindra_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
d2_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="EqShCap",])

dp2_mahindra=ggplot(d2_mahindra, aes(x = Year, y = Amount)) +
  geom_point(col = "darkblue", size = 5) +
  geom_line(aes(group = 1), col = "pink", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in Crores",
    title = "Equity Share Capital",
    caption = "Cleaned by Team",
    subtitle = "Mahindra & Mahindra Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(596, 600),            # Set y-axis limits
    breaks = seq(596, 600, by = 1), # Set the breaks on the y-axis
    labels = seq(596, 600, by = 1)     # Label the y-axis with values from 596 to 600
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
d3_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="Res_Surp",])

dp3_mahindra=ggplot(d3_mahindra, aes(x = Year, y = Amount)) +
  geom_point(col = "darkblue", size = 5) +
  geom_line(aes(group = 1), col = "pink", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in 000's(cr.)",
    title = "Reserves & Surplus",
    caption = "Cleaned by Team",
    subtitle = "Mahindra & Mahindra Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(32000, 53000),              # Set y-axis limits
    breaks = seq(32000, 53000, by = 3000), # Set the breaks on the y-axis
    labels = seq(32, 53, by = 3)           # Label the y-axis with values from 32 to 53
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
d4_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="EqShApMony",])

dp4_mahindra=ggplot(d4_mahindra, aes(x = Year, y = Amount)) +
  geom_point(col = "darkblue", size = 5) +
  geom_line(aes(group = 1), col = "pink", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in Crores",
    title = "Equity Share Application Money",
    caption = "Cleaned by Team",
    subtitle = "Mahindra & Mahindra Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(215, 305),            # Set y-axis limits
    breaks = seq(215, 305, by = 10), # Set the breaks on the y-axis
    labels = seq(215, 305, by = 10)     # Label the y-axis with values from 215 to 305
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Total Shareholders' Funds

grid.arrange(
  dp2_mahindra, dp4_mahindra,  # First row: Two charts
  dp3_mahindra,            # Second row: One wide chart
  nrow = 2,            # 2 rows
  ncol = 2,            # 2 columns
  layout_matrix = rbind(c(1, 2),  # Top two plots
                        c(3, 3)), # Bottom plot spans full width
  heights = c(1.75, 2)  # Give more space to bottom chart
)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

mahindra_bs_long<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
# Inspect the data structure
head(mahindra_bs_long)
Items 2024 2023 2022 2021 2020 Category
EqShCap 599.62 599.05 598.30 597.39 596.52 SholderFunds
Res_Surp 51378.18 42497.35 38139.19 33649.65 33606.36 SholderFunds
EqShApMony 298.76 260.33 223.46 254.88 264.96 SholderFunds
LTBor 1134.86 2331.56 5678.02 7070.03 2032.03 NonCurLiab
DTL_Net 1555.06 1470.29 1700.80 1343.15 1408.17 NonCurLiab
Other_LTB 1678.92 1374.15 1057.54 585.11 698.22 NonCurLiab
# Filtering Total Debt from the mahindra_bs_long
total_debt_madhindra <- mahindra_bs_long[mahindra_bs_long$Items %in% c("LTBor"), ]

# Filtering Total Shareholders' Funds from the mahindra_bs_long
total_shareholders_funds_mahindra <- mahindra_bs_long[mahindra_bs_long$Items %in% c("EqShCap", "Res_Surp", "EqShApMony"), ]

# Sum Total Debts and Total Shareholders' Funds for each year 2024 to 2020
total_debt_madhindra_sum <- colSums(total_debt_madhindra[, 2:6]) 
total_shareholders_funds_mahindra_sum <- colSums(total_shareholders_funds_mahindra[,2:6])  

# Calculate Debt-to-Equity Ratio
debt_equity_ratio_mahindra <- total_debt_madhindra_sum / total_shareholders_funds_mahindra_sum

# Displaying the Debt-to-Equity Ratio
debt_equity_ratio_mahindra
##       2024       2023       2022       2021       2020 
## 0.02170877 0.05377620 0.14573618 0.20491700 0.05895438
#Create a data frame for plotting
debt_equity_ratio_mahindra_data <- data.frame(
  Year = as.numeric(names(debt_equity_ratio_mahindra)),  # Extract years from names
  debt_equity_ratio_mahindra = as.numeric(debt_equity_ratio_mahindra)  # Convert values to numeric
)

#line plot
# Plot Debt-to-Equity Ratio
ggplot(debt_equity_ratio_mahindra_data, aes(x = Year, y = debt_equity_ratio_mahindra)) +
  geom_line(color = "darkorange", linewidth = 1.5) +  # Use linewidth for line thickness
  geom_point(color = "brown", size = 3.5) +     # Add points for each year
  labs(
    title = "Debt-to-Equity Trend for Mahindra & Mahindra (2020–2024)",
    x = "Year",
    y = "Debt-to-Equity Ratio"
  ) +
  scale_y_continuous(
    limits = c(0, 0.25), # Set y-axis limits
    breaks = seq(0, 0.25, by =0.05), # Set the breaks on the y-axis
    labels = seq(0, 0.25, by = 0.05)  # Label the y-axis with values from 0 to 0.25
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Bar Plot for Debt-to-Equity Ratio (Mahindra & Mahindra)
ggplot(debt_equity_ratio_mahindra_data, aes(x = factor(Year), y = debt_equity_ratio_mahindra, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(
    title = "Debt-to-Equity Trend for Mahindra & Mahindra (2020–2024)",
    x = "Year",
    y = "Debt-to-Equity Ratio"
  ) +
  scale_fill_manual(values = c("2024" = "red", "2023" = "blue",
                               "2022" = "orange", "2021" = "green", "2020" = "purple")) +
  geom_text(aes(label = round(debt_equity_ratio_mahindra, 3)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(0, 0.25),                            # Adjusted y-axis limits for better visualization
    breaks = seq(0, 0.25, by = 0.05),               # Set breaks on y-axis
    labels = scales::label_number(accuracy = 0.001) # Format labels to 3 decimal places
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Load ggplot2 library
library(ggplot2)

# Create DF for Debt-Equity Ratio
debt_equity_data <- data.frame(
  Year = rep(c(2020, 2021, 2022, 2023, 2024), 2),
  Company = c(rep("Tata Motors", 5), rep("Mahindra & Mahindra", 5)),
  Debt_Equity_Ratio = c(0.8434, 0.8568, 0.7071, 0.4649, 0.1737,  
                        0.0590, 0.2049, 0.1457, 0.0538, 0.0217)  
)

# Bar Chart
ggplot(debt_equity_data, aes(x = factor(Year), y = Debt_Equity_Ratio, fill = Company)) +
  geom_bar(stat = "identity", position = "dodge", color = "black", linewidth = 1) +
  labs(title = "Debt-Equity Ratio: Tata Motors vs Mahindra & Mahindra", 
       subtitle = "(2020-2024)",
       x = "Year", 
       y = "Debt-Equity Ratio",
       caption = "Source: Financial Reports of Tata Motors & Mahindra & Mahindra") +
  scale_fill_manual(values = c("Tata Motors" = "steelblue",  
                               "Mahindra & Mahindra" = "darkorange")) +  
  geom_text(aes(label = round(Debt_Equity_Ratio, 4)), 
            position = position_dodge(width = 0.9), 
            vjust = -0.3,  
            size = 5, color = "black", fontface = "bold") +  
  scale_y_continuous(
    limits = c(0, 1),  
    breaks = seq(0, 1, by = 0.2)  
  ) + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 18, color = "black"),
    plot.subtitle = element_text(hjust = 0.5, size = 14, color = "gray40"),
    axis.title = element_text(size = 14, face = "bold"),
    axis.text = element_text(size = 12),
    legend.position = "top",
    legend.title = element_blank(),
    legend.text = element_text(size = 12, face = "bold"),
    panel.border = element_rect(color = "black", fill = NA, linewidth = 1.5)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

Conclusion:

Tata Motors has a higher debt-equity ratio, indicating greater reliance on debt financing, though it shows a declining trend over the years. Mahindra & Mahindra maintains a much lower debt-equity ratio, reflecting a more conservative approach to debt and stronger financial stability.

Strengths & Stumbling Blocks 🔍

Weekness

LIQUIDITY

TATA MOTORS QUICK RATIO

BY SHUSHAL

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Quick Ratio
#Quick Ratio = Quick Asset/Current Liability
#First Step --> Quick Asset

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
qr1_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Cash_CE",])

qrp1_tata=ggplot(qr1_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Cash & Cash Equivalents",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1200, 5400),  # Set y-axis limits
    breaks = seq(1200, 5400, by = 600),  # Set the breaks on the y-axis
    labels = seq(12, 54, by = 6), # Label the y-axis with values from 12 to 54
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
qr2_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="CurInvst",])

qrp2_tata=ggplot(qr1_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Current Investments",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(600, 5400),  # Set y-axis limits
    breaks = seq(600, 5400, by = 600),  # Set the breaks on the y-axis
    labels = seq(6, 54, by = 6), # Label the y-axis with values from 6 to 54
  ) + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )
#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team3
qr3_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="ST_LoanAdv",])

qrp3_tata=ggplot(qr3_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Short-Term Loans & Advances",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(120, 240),  # Set y-axis limits
    breaks = seq(120, 240, by = 20),  # Set the breaks on the y-axis
    labels = seq(120, 240, by = 20),# Label the y-axis with values from 120 to 240
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )  

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
qr4_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="TR",])

qrp4_tata=ggplot(qr4_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Trade Receivables",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1700, 2900),  # Set y-axis limits
    breaks = seq(1700, 2900, by = 200),  # Set the breaks on the y-axis
    labels = seq(17, 29, by = 2),# Label the y-axis with values from 17 to 29
  )  +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Quick Assets

grid.arrange(qrp1_tata,qrp2_tata,qrp3_tata,qrp4_tata,nrow=2,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Quick Ratio = Quick Asset/current Liability
#Second Step --> Current Liability

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL
#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 5
qr5_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="OCurrLiab",])

qrp5_tata=ggplot(qr5_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Other Current Liability",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(8000, 12000),  # Set y-axis limits
    breaks = seq(8000, 12000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(8, 12, by = 1),# Label the y-axis with values from 8 to 12
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 6
qr6_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="STBor",])

qrp6_tata=ggplot(qr6_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Short-Term Borrowings",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(4000, 10000),  # Set y-axis limits
    breaks = seq(4000, 10000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(4, 10, by = 1),# Label the y-axis with values from 4 to 10
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 7
qr7_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="STProv",])

qrp7_tata=ggplot(qr7_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Short-Term Provisions",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(200, 1600),  # Set y-axis limits
    breaks = seq(200, 1600, by = 200),  # Set the breaks on the y-axis
    labels = seq(2, 16, by = 2), # Label the y-axis with values from 2 to 16
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 8
qr8_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="TP",])

qrp8_tata=ggplot(qr8_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="skyblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Trade Payables",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(5500, 9500),  # Set y-axis limits
    breaks = seq(5500, 9500, by = 500),  # Set the breaks on the y-axis
    labels = seq(55, 95, by = 5), # Label the y-axis with values from 55 to 95
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Current Liability

grid.arrange(qrp5_tata,qrp6_tata,qrp7_tata,qrp8_tata,nrow=2,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

tata_bs_long<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
# Inspect the data structure
head(tata_bs_long)
Items 2024 2023 2022 2021 2020 Category
EqShCap 766.50 766.02 765.88 765.81 719.54 SholderFunds
Res_Surp 29374.83 21701.37 19171.88 18290.16 16800.61 SholderFunds
EqShApMony 1.72 2.46 6.39 0.00 0.00 SholderFunds
LTBor 5235.67 10445.70 14102.74 16326.77 14776.51 NonCurLiab
DTL_Net 49.78 51.16 173.72 266.50 198.59 NonCurLiab
Other_LTB 1392.16 1411.78 1212.34 1786.93 1646.56 NonCurLiab
# Filtering Quick Assets from the tata_bs_long
quick_assets <- tata_bs_long[tata_bs_long$Items %in% c("CurInvst", "TR", "Cash_CE","ST_LoanAdv"), ]

# Filtering Current Liabilities from the tata_bs_long
current_liabilities <- tata_bs_long[tata_bs_long$Items %in% c("STBor", "TP", "OCurrLiab", "STProv"), ]

# Sum Quick Assets and Current Liabilities for each year 2024 to 2020
quick_assets_sum <- colSums(quick_assets[, 2:6]) 
current_liabilities_sum <- colSums(current_liabilities[,2:6])  

# Calculate quick ratio
quick_ratio <- quick_assets_sum / current_liabilities_sum

# Displaying the quick ratio
quick_ratio
##      2024      2023      2022      2021      2020 
## 0.3674797 0.2711885 0.3704564 0.3111892 0.2567799
#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Create a data frame for plotting
quick_ratio_data <- data.frame(
  Year = as.numeric(names(quick_ratio)),  # Extract year names
  quick_ratio = as.numeric(quick_ratio) # Convert ratios to numeric
)

# Plot Quick Ratio Trend
ggplot(quick_ratio_data, aes(x = Year, y = quick_ratio)) +
  geom_line(color = "yellow", linewidth = 1.5) +  # Line thickness
  geom_point(color = "brown", size = 3.5) +      # Points on each year
  labs(
    title = "Quick Ratio Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Quick Ratio"
  ) +
  scale_y_continuous(
    limits = c(0.23, 0.38), # Set y-axis limits
    breaks = seq(0.23, 0.38, by = 0.05), # Set the breaks on the y-axis
    labels = scales::label_number(accuracy = 0.01), # Label the y-axis with values from 0.23 to 0.38
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Bar Plot for Quick Ratio
ggplot(quick_ratio_data, aes(x = factor(Year), y = quick_ratio, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(
    title = "Quick Ratio Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Quick Ratio"
  ) +
  scale_fill_manual(values = c("2024" = "red", "2023" = "blue",
                               "2022" = "orange", "2021" = "green", "2020" = "purple")) +
  geom_text(aes(label = round(quick_ratio, 3)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(0, 0.40),                           # Adjusted y-axis limits for Quick Ratio
    breaks = seq(0, 0.40, by = 0.05),              # Set breaks on y-axis
    labels = scales::label_number(accuracy = 0.001)   # Format labels to 3 decimal places
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

SOLVENCY

TATA MOTORS DEBT TO EQUITY RATIO

BY HAREESH R

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------



#Finding Debt-to-Equity Ratio
#Debt-to-Equity Ratio = Total Debt/Total Shareholders' Equity
#First step --> Finding Total Debt

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
d1_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="LTBor",])

dp1_tata=ggplot(d1_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkviolet",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="gold",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Long-Term Borrowings",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(4000, 18000),  # Set y-axis limits
    breaks = seq(4000, 18000, by = 2000),  # Set the breaks on the y-axis
    labels = seq(4, 18, by = 2), # Label the y-axis with values from 4 to 18
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Debt-to-Equity Ratio = Total Debt/Total Shareholders' Equity

#Second step --> Finding Total Shareholders' Equity

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
d2_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="EqShCap",])

dp2_tata=ggplot(d2_tata, aes(x = Year, y = Amount)) +
  geom_point(col = "darkviolet", size = 5) +
  geom_line(aes(group = 1), col = "gold", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in Crores",
    title = "Equity Share Capital",
    caption = "Cleaned by Team",
    subtitle = "TATA Motors Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(710, 780),            # Set y-axis limits
    breaks = seq(710, 780, by = 10), # Set the breaks on the y-axis
    labels = seq(710, 780, by = 10)     # Label the y-axis with values from 710 to 780
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
d3_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Res_Surp",])

dp3_tata=ggplot(d3_tata, aes(x = Year, y = Amount)) +
  geom_point(col = "darkviolet", size = 5) +
  geom_line(aes(group = 1), col = "gold", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in 000's(cr.)",
    title = "Reserves & Surplus",
    caption = "Cleaned by Team",
    subtitle = "TATA Motors Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(15000, 31000),            # Set y-axis limits
    breaks = seq(15000, 31000, by = 2000), # Set the breaks on the y-axis
    labels = seq(15, 31, by = 2)     # Label the y-axis with values from 15 to 31
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
d4_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="EqShApMony",])

dp4_tata=ggplot(d4_tata, aes(x = Year, y = Amount)) +
  geom_point(col = "darkviolet", size = 5) +
  geom_line(aes(group = 1), col = "gold", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in Crores",
    title = "Equity Share Application Money",
    caption = "Cleaned by Team",
    subtitle = "TATA Motors Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(0, 7),            # Set y-axis limits
    breaks = seq(0, 7, by = 1),  # Set the breaks on the y-axis
    labels = seq(0, 7, by = 1)   # Label the y-axis with values from 0 to 7
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )
   
#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Total Shareholders' Funds

grid.arrange(
  dp2_tata, dp4_tata,  # First row: Two charts
  dp3_tata,            # Second row: One wide chart
  nrow = 2,            # 2 rows
  ncol = 2,            # 2 columns
  layout_matrix = rbind(c(1, 2),  # Top two plots
                        c(3, 3)), # Bottom plot spans full width
  heights = c(1.5, 1.75)  # Give more space to bottom chart
)

#-----------------------------------------------------------------------------------------------------------------------------------------------------
#Debt-to-Equity Ratio = Total Debt/Total Shareholders' Equity

tata_bs_long<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
# Inspect the data structure
head(tata_bs_long)
Items 2024 2023 2022 2021 2020 Category
EqShCap 766.50 766.02 765.88 765.81 719.54 SholderFunds
Res_Surp 29374.83 21701.37 19171.88 18290.16 16800.61 SholderFunds
EqShApMony 1.72 2.46 6.39 0.00 0.00 SholderFunds
LTBor 5235.67 10445.70 14102.74 16326.77 14776.51 NonCurLiab
DTL_Net 49.78 51.16 173.72 266.50 198.59 NonCurLiab
Other_LTB 1392.16 1411.78 1212.34 1786.93 1646.56 NonCurLiab
# Filtering Total Debt from the tata_bs_long
total_debt <- tata_bs_long[tata_bs_long$Items %in% c("LTBor"), ]

# Filtering Total Shareholders' Funds from the tata_bs_long
total_shareholders_funds <- tata_bs_long[tata_bs_long$Items %in% c("EqShCap", "Res_Surp", "EqShApMony"), ]

# Sum Total Debts and Total Shareholders' Funds for each year 2024 to 2020
total_debt_sum <- colSums(total_debt[, 2:6]) 
total_shareholders_funds_sum <- colSums(total_shareholders_funds[,2:6])  

# Calculate Debt-to-Equity Ratio
debt_equity_ratio <- total_debt_sum / total_shareholders_funds_sum

# Displaying the Debt-to-Equity Ratio
debt_equity_ratio
##      2024      2023      2022      2021      2020 
## 0.1736941 0.4648763 0.7071116 0.8567798 0.8434009
#Create a data frame for plotting
debt_equity_ratio_data <- data.frame(
  Year = as.numeric(names(debt_equity_ratio)),  # Extract years from names
  debt_equity_ratio = as.numeric(debt_equity_ratio)  # Convert values to numeric
)
#-----------------------------------------------------------------------------------------------------------------------------------------------------
#line plot
#Plot Debt-to-Equity Ratio
  ggplot(debt_equity_ratio_data, aes(x = Year, y = debt_equity_ratio)) +
    geom_line(color = "cyan", linewidth = 1.5) +  # Use linewidth for line thickness
    geom_point(color = "red", size = 3.5) +     # Add points for each year
    labs(
      title = "Debt-to-Equity Trend for Tata Motors (2020–2024)",
      x = "Year",
      y = "Debt-to-Equity Ratio"
    ) +
    scale_y_continuous(
      limits = c(0, 1), # Set y-axis limits
      breaks = seq(0, 1, by = 0.1), # Set the breaks on the y-axis
      labels = seq(0, 1, by = 0.1)  # Label the y-axis with values from 0 to 1
    ) +
    theme_minimal() +
    theme(
      plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
      axis.title = element_text(size = 12),
      axis.text = element_text(size = 10)
    )

#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Bar Plot for Debt-to-Equity Ratio
ggplot(debt_equity_ratio_data, aes(x = factor(Year), y = debt_equity_ratio, fill = debt_equity_ratio)) +
  geom_bar(stat = "identity", color = "black", width = 0.6) +  # border
  geom_text(aes(label = round(debt_equity_ratio, 2)), vjust = -0.5, size = 5, fontface = "bold") +  
  labs(
    title = "Debt-to-Equity Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Debt-to-Equity Ratio"
  ) +
  scale_y_continuous(
    limits = c(0, 1), # Set y-axis limits
    breaks = seq(0, 1, by = 0.1), # Set the breaks on the y-axis
    labels = seq(0, 1, by = 0.1)  # Label the y-axis with values from 0 to 1
  ) +
  scale_fill_gradient(low = "skyblue", high = "darkblue") + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10),
    legend.position = "none"
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

PROFITABILITY

TATA MOTORS NET PROFIT MARGIN RATIO

BY GOUTHAM S

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
tata_pl<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
tata_pl<-as.data.frame(tata_pl)

#clean the column names
colnames(tata_pl)<-make.names(colnames(tata_pl))
colnames(tata_pl)<-trimws(colnames(tata_pl))

#reshaping the data to long format
tata_pl_long<-reshape(tata_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Net Profit Margin
#Net Profit Margin = [(Net Profit/Loss) / Revenue] * 100
#First Step --> Net Profit/Loss

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
npm1_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="Net_PorL",])

npmp1_tata=ggplot(npm1_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkcyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Net Profit or Loss for the Period",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(min(npm1_tata$Amount, na.rm = TRUE), max(npm1_tata$Amount, na.rm = TRUE)),
    breaks = seq(-7500, 8500, by = 2000),  
    labels = seq(-75, 85, by = 20)
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Net Profit Margin = [(Net Profit/Loss) / Revenue] * 100
#Second Revenue

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
tata_pl<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
tata_pl<-as.data.frame(tata_pl)

#clean the column names
colnames(tata_pl)<-make.names(colnames(tata_pl))
colnames(tata_pl)<-trimws(colnames(tata_pl))

#reshaping the data to long format
tata_pl_long<-reshape(tata_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
npm2_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="Revenue_Op",])

npmp2_tata=ggplot(npm2_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkcyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Revenue From Operations",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(25000, 75000),  # Set y-axis limits
    breaks = seq(25000, 75000, by = 10000),  # Set the breaks on the y-axis
    labels = seq(25, 75, by = 10),# Label the y-axis with values from 25 to 75
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
npm3_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="OtherOpRev",])

npmp3_tata=ggplot(npm3_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkcyan",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Other Operating Revenue",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(350, 600),  # Set y-axis limits
    breaks = seq(350, 600, by = 50),  # Set the breaks on the y-axis
    labels = seq(350, 600, by = 50),# Label the y-axis with values from 350 to 600
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
npm4_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="OtherInc",])

npmp4_tata=ggplot(npm4_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkcyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Other Income",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(300, 1500),  # Set y-axis limits
    breaks = seq(300, 1500, by = 200),  # Set the breaks on the y-axis
    labels = seq(3, 15, by = 2), # Label the y-axis with values from 3 to 15
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )   

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Total Revenue

grid.arrange(
  npmp4_tata, npmp3_tata,  # First row: Two charts
  npmp2_tata,            # Second row: One wide chart
  nrow = 2,            # 2 rows
  ncol = 2,            # 2 columns
  layout_matrix = rbind(c(1, 2),  # Top two plots
                        c(3, 3)), # Bottom plot spans full width
  heights = c(1.5, 1.75)  # Give more space to bottom chart
)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Filtering Net Profit/Loss from tata_pl_long
net_profit_loss <- npm1_tata
#reset row names
row.names(net_profit_loss)<-NULL

#Filtering Revenure from the tata_pl_long
revenue <- tata_pl_long[tata_pl_long$Items %in% c("Revenue_Op", "OtherOpRev", "OtherInc"), ]

#Sum Revenue and Net Profit/Loss for each year 2024 to 2020
revenue_total <- aggregate(Amount ~ Year, revenue, sum)
net_profit_loss_total <- aggregate(Amount ~ Year, net_profit_loss, sum)

print(net_profit_loss_total)
##   Year   Amount
## 1 2020 -7289.63
## 2 2021 -2395.44
## 3 2022 -1390.86
## 4 2023  2728.13
## 5 2024  7902.08
print(revenue_total)
##   Year   Amount
## 1 2020 45311.22
## 2 2021 30595.02
## 3 2022 47923.59
## 4 2023 66578.27
## 5 2024 74452.96
#Calculate Net Profit Margin
#Convert Year to numeric
#Ensure Amount to numeric
net_profit_loss_total$Amount <- as.numeric(net_profit_loss_total$Amount)
revenue_total$Amount <- as.numeric(revenue_total$Amount)

#Compute Net Profit Ratio for each year
net_profit_margin <- (net_profit_loss_total$Amount / revenue_total$Amount) * 100

print(net_profit_margin)
## [1] -16.087914  -7.829510  -2.902245   4.097628  10.613520
#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Create the data frame for plotting
net_profit_margin_data <- data.frame(
  Year = as.numeric(net_profit_loss_total$Year),  # Extract Year from net_profit_loss_total
  net_profit_margin = net_profit_margin  # Use the computed vector directly
)

  #Plot Net Profit Margin Ratio
ggplot(net_profit_margin_data, aes(x = Year, y = net_profit_margin)) +
  geom_line(color = "hotpink", linewidth = 1.5) +  
  geom_point(color = "blue", size = 3.5) +       
  labs(
    title = "Net Profit Margin for Tata Motors (2020–2024)",
    x = "Year",
    y = "Net Profit Margin"
  ) +
  scale_y_continuous(
    limits = c(-18, 12), # Set y-axis limits
    breaks = seq(-18, 12, by = 2), # Set the breaks on the y-axis
    labels = seq(-18, 12, by = 2),  # Label the y-axis with values from -18 to 12 
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#-----------------------------------------------------------------------------------------------------------------------------------------------------
#Load ggplot2 library
library(ggplot2)

#Bar plot for Net Profit Margin
ggplot(net_profit_margin_data, aes(x = factor(Year), 
                                   y = net_profit_margin, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(title = "Net Profit Margin (2020 - 2024)", x = "Year",
       y = "Net Profit Margin (%)") +
  scale_fill_manual(values = c("2024" = "hotpink", "2023" = "green",
                               "2022" = "grey", "2021" = "blue", "2020" = "red")) +
  geom_text(aes(label = round(net_profit_margin, 2)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(-18, 12), # Set y-axis limits
    breaks = seq(-18, 12, by = 2), # Set breaks on y-axis
    labels = seq(-18, 12, by = 2),  # Label the y-axis with values from -18 to 12 
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

##Strengths

LIQUIDITY

TATA MOTORS CURRENT RATIO

BY GOUTHAM S

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Current Ratio
#Current Ratio = current Asset/current Liability
#First Step --> Current Asset

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
cr1_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Cash_CE",])

crp1_tata=ggplot(cr1_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Cash & Cash Equivalents",
       caption = "Cleaned by Team",
       subtitle= "TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1200, 5400),  # Set y-axis limits
    breaks = seq(1200, 5400, by = 600),  # Set the breaks on the y-axis
    labels = seq(12, 54, by = 6), # Label the y-axis with values from 12 to 54
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
cr2_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="CurInvst",])

crp2_tata=ggplot(cr2_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Current Investments",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(600, 5400),  # Set y-axis limits
    breaks = seq(600, 5400, by = 800),  # Set the breaks on the y-axis
    labels = seq(6, 54, by = 8), # Label the y-axis with values from 6 to 54
  ) + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
cr3_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Inv",])

crp3_tata=ggplot(cr3_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Inventory",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(2500, 5000),  # Set y-axis limits
    breaks = seq(2500, 5000, by = 500),  # Set the breaks on the y-axis
    labels = seq(25, 50, by = 5), # Label the y-axis with values from 25 to 50
) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
cr4_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="OCurrAst",])

crp4_tata=ggplot(cr4_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Other Current Asset",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1200, 3300),  # Set y-axis limits
    breaks = seq(1200, 3300, by = 300),  # Set the breaks on the y-axis
    labels = seq(12, 33, by = 3),# Label the y-axis with values from 12 to 33
 ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 5
cr5_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="ST_LoanAdv",])

crp5_tata=ggplot(cr5_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Short-Term Loans & Advances",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(120, 240),  # Set y-axis limits
    breaks = seq(120, 240, by = 20),  # Set the breaks on the y-axis
    labels = seq(120, 240, by = 20),# Label the y-axis with values from 120 to 240
) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 6
cr6_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="TR",])

crp6_tata=ggplot(cr6_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Trade Receivables",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1900, 2900),  # Set y-axis limits
    breaks = seq(1900, 2900, by = 200),  # Set the breaks on the y-axis
    labels = seq(19, 29, by = 2),# Label the y-axis with values from 19 to 29
)  +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )  

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Current Assets

grid.arrange(crp1_tata,crp2_tata,crp3_tata,crp4_tata,crp5_tata,crp6_tata,nrow=3,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Pie chart
library(ggplot2)
library(dplyr)

# Filtering Current Assets from the tata_bs_long
current_assets <- tata_bs_long[tata_bs_long$Items %in% c("CurInvst", "Inv", "TR", "Cash_CE", "OCurrAst","ST_LoanAdv"), ]

# Filter for the last 5 years and sum amounts by Items
current_assets_total <- current_assets %>%
  filter(Year %in% c(2024, 2023, 2022, 2021, 2020)) %>%  # Keeping only required years
  group_by(Items) %>%  # Group by Items
  summarise(Total_Amount = sum(Amount, na.rm = TRUE))  # Adding Amount column

# correct labels
item_labels <- c(
  "CurInvst" = "Current Investments",
  "Inv" = "Inventory",
  "TR" = "Trade Receivables",
  "Cash_CE" = "Cash & Cash Equivalents",
  "ST_LoanAdv" = "Short-Term Loans & Advances",
  "OCurrAst" = "Other Current Assets"
)

# Pie Chart for Total Current Assets Distribution
ggplot(current_assets_total, aes(x = "", y = Total_Amount, fill = Items)) +
  geom_bar(stat = "identity", width = 2.5, color = "black") +  # Outline added
  coord_polar(theta = "y") +  
  labs(title = "Total Current Assets Distribution (2020-2024)", fill = "Items") +
  
  # Custom Colors
  scale_fill_manual(values = c(
    "CurInvst" = "yellow", 
    "Inv" = "lightblue",   
    "TR" = "green",  
    "Cash_CE" = "grey",    
    "ST_LoanAdv" = "hotpink", 
    "OCurrAst" = "orange" 
  )) + 
  
  # Labels inside the pie chart (Centred)
  geom_text(aes(label = paste0(item_labels[Items], "\n", 
                               round((Total_Amount / sum(Total_Amount)) * 100, 1), "%")), 
            position = position_stack(vjust = 0.5), 
            size = 3.5, color = "black", fontface = "bold") +
  theme_minimal() +
  theme(
    axis.title = element_blank(),
    axis.text = element_blank(),
    panel.grid = element_blank(),
    plot.title = element_text(hjust = 0.5, face = "bold", size = 15)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Current ratio = current asset/current liability
#Second Step --> current Liability

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 7
cr7_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="OCurrLiab",])

crp7_tata=ggplot(cr7_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Other Current Liability",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(8000, 12000),  # Set y-axis limits
    breaks = seq(8000, 12000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(8, 12, by = 1),# Label the y-axis with values from 8 to 12
) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 8
cr8_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="STBor",])

crp8_tata=ggplot(cr8_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Short-Term Borrowings",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(5000, 10000),  # Set y-axis limits
    breaks = seq(5000, 10000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(5, 10, by = 1),# Label the y-axis with values from 5 to 10
) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 9
cr9_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="STProv",])

crp9_tata=ggplot(cr9_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Short-Term Provisions",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(300, 1500),  # Set y-axis limits
    breaks = seq(300, 1500, by = 300),  # Set the breaks on the y-axis
    labels = seq(3, 15, by = 3), # Label the y-axis with values from 3 to 15
) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 10
cr10_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="TP",])

crp10_tata=ggplot(cr10_tata,aes(x=Year,y=Amount))+
  geom_point(col="navy",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="hotpink",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Trade Payables",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(5000, 10000),  # Set y-axis limits
    breaks = seq(5000, 10000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(5, 10, by = 1), # Label the y-axis with values from 5 to 10
) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )   
#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - total Liability

grid.arrange(crp7_tata,crp8_tata,crp9_tata,crp10_tata,nrow=2,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Pie chart
library(ggplot2)
library(dplyr)

# Filtering Current Liabilities from the tata_bs_long
current_liabilities <- tata_bs_long[tata_bs_long$Items %in% c("STBor", "TP", "OCurrLiab", "STProv"), ]

# Filter for the last 5 years and sum amounts by Items
current_liablities_total <- current_liabilities %>%
  filter(Year %in% c(2024, 2023, 2022, 2021, 2020)) %>%  # Keeping only required years
  group_by(Items) %>%  # Group by Items
  summarise(Total_Amount = sum(Amount, na.rm = TRUE))  # Adding Amount column

library(plotrix)

# pie chart input
items <- c("Current Investment", "Inventory", "Trade Receivables", "Cash and Cash Equivalents", "Short-Term Loans and Advances", "Other Current Assets")
values <- c(200, 300, 150, 250, 180, 220)  # Example total amounts
colors <- c("yellow", "lightblue", "green", "grey", "hotpink", "orange")

# 3D Pie Chart
pie3D(values, labels = paste0(items, "\n", round(values / sum(values) * 100, 1), "%"),
      col = colors, explode = 0.05, main = "Total Current Assets Distribution (2020-2024)")

#-----------------------------------------------------------------------------------------------------------------------------------------------------

tata_bs_long<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
# Inspect the data structure
head(tata_bs_long)
Items 2024 2023 2022 2021 2020 Category
EqShCap 766.50 766.02 765.88 765.81 719.54 SholderFunds
Res_Surp 29374.83 21701.37 19171.88 18290.16 16800.61 SholderFunds
EqShApMony 1.72 2.46 6.39 0.00 0.00 SholderFunds
LTBor 5235.67 10445.70 14102.74 16326.77 14776.51 NonCurLiab
DTL_Net 49.78 51.16 173.72 266.50 198.59 NonCurLiab
Other_LTB 1392.16 1411.78 1212.34 1786.93 1646.56 NonCurLiab
# Filtering Current Assets from the tata_bs_long
current_assets <- tata_bs_long[tata_bs_long$Items %in% c("CurInvst", "Inv", "TR", "Cash_CE", "OCurrAst","ST_LoanAdv"), ]

# Filtering Current Liabilities from the tata_bs_long
current_liabilities <- tata_bs_long[tata_bs_long$Items %in% c("STBor", "TP", "OCurrLiab", "STProv"), ]

# Sum Current Assets and Current Liabilities for each year 2024 to 2020
current_assets_sum <- colSums(current_assets[, 2:6]) 
current_liabilities_sum <- colSums(current_liabilities[,2:6])  

# Calculate Current Ratio
current_ratio <- current_assets_sum / current_liabilities_sum

# Displaying the Current Ratio
current_ratio
##      2024      2023      2022      2021      2020 
## 0.5565242 0.4456735 0.5786582 0.6039487 0.5257005
# Create a data frame for plotting
current_ratio_data <- data.frame(
  Year = as.numeric(names(current_ratio)),  # Extract year names
  Current_Ratio = as.numeric(current_ratio) # Convert ratios to numeric
)

# Plot = Current Ratio
ggplot(current_ratio_data, aes(x = Year, y = Current_Ratio)) +
  geom_line(color = "red", linewidth = 1.5) +  # Use linewidth for line thickness
  geom_point(color = "blue", size = 3.5) +        # Add points for each year
  labs(
    title = "Current Ratio Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Current Ratio"
  ) +
  scale_y_continuous(
    limits = c(0.42, 0.62), # Set y-axis limits
    breaks = seq(0.42, 0.62, by = 0.04), # Set the breaks on the y-axis
    labels = scales::label_number(accuracy = 0.01), # Label the y-axis with values from 0.42 to 0.62
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load required libraries
library(ggplot2)

# Create bar plot
ggplot(current_ratio_data, aes(x = factor(Year), 
                               y = Current_Ratio, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(title = "Current Ratio from (2020 - 2024)", x = "Year",
       y = "Current Ratio") +
  scale_fill_manual(values = c("2024" = "blue", "2023" = "red",
                               "2022" = "green", "2021" = "navy", "2020" = "orange")) +
  geom_text(aes(label = round(Current_Ratio, 2)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(0, 0.65), # Set y-axis limits
    breaks = seq(0, 0.65, by = 0.05), # Set the breaks on the y-axis
    labels = scales::label_number(accuracy = 0.01), # Label the y-axis with values from 0.40 to 0.70
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

LIQUIDITY

TATA MOTORS CASH RATIO

BY SHUSHAL

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Cash Ratio
#Cash ratio = Cash & cash Equivalents /Current Liability
#First Step --> Cash & Cash equivalents

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
cashr1_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Cash_CE",])

cashrp1_tata=ggplot(cashr1_tata,aes(x=Year,y=Amount))+
  geom_point(col="red",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="cyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Cash & Cash Equivalents",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1000, 5500),  # Set y-axis limits
    breaks = seq(1000, 5500, by = 500),  # Set the breaks on the y-axis
    labels = seq(10, 55, by = 5), # Label the y-axis with values from 10 to 55
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Cash ratio = Cash & Cash Equivalents/Current Liability
#Second Step --> Current Liability

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL
#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
cashr2_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="OCurrLiab",])

cashrp2_tata=ggplot(cashr2_tata,aes(x=Year,y=Amount))+
  geom_point(col="red",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="cyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Other Current Liability",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(8000, 12000),  # Set y-axis limits
    breaks = seq(8000, 12000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(8, 12, by = 1),# Label the y-axis with values from 8 to 12
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
cashr3_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="STBor",])

cashrp3_tata=ggplot(cashr3_tata,aes(x=Year,y=Amount))+
  geom_point(col="red",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="cyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Short-Term Borrowings",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(4000, 10000),  # Set y-axis limits
    breaks = seq(4000, 10000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(4, 10, by = 1),# Label the y-axis with values from 4 to 10
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
cashr4_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="STProv",])

cashrp4_tata=ggplot(cashr4_tata,aes(x=Year,y=Amount))+
  geom_point(col="red",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="cyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Short-Term Provisions",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(200, 1600),  # Set y-axis limits
    breaks = seq(200, 1600, by = 200),  # Set the breaks on the y-axis
    labels = seq(2, 16, by = 2), # Label the y-axis with values from 2 to 16
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 5
cashr5_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="TP",])

cashrp5_tata=ggplot(cashr5_tata,aes(x=Year,y=Amount))+
  geom_point(col="red",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="cyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Trade Payables",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(5500, 9500),  # Set y-axis limits
    breaks = seq(5500, 9500, by = 500),  # Set the breaks on the y-axis
    labels = seq(55, 95, by = 5), # Label the y-axis with values from 55 to 95
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Current Liability

grid.arrange(cashrp2_tata,cashrp3_tata,cashrp4_tata,cashrp5_tata,nrow=2,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

tata_bs_long<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
# Inspect the data structure
head(tata_bs_long)
Items 2024 2023 2022 2021 2020 Category
EqShCap 766.50 766.02 765.88 765.81 719.54 SholderFunds
Res_Surp 29374.83 21701.37 19171.88 18290.16 16800.61 SholderFunds
EqShApMony 1.72 2.46 6.39 0.00 0.00 SholderFunds
LTBor 5235.67 10445.70 14102.74 16326.77 14776.51 NonCurLiab
DTL_Net 49.78 51.16 173.72 266.50 198.59 NonCurLiab
Other_LTB 1392.16 1411.78 1212.34 1786.93 1646.56 NonCurLiab
#Filtering Cash & Cash Equivalents from the tata_bs_long
cash_cash_equivalents <- tata_bs_long[tata_bs_long$Items %in% c("Cash_CE"), ]

#Filtering Current Liabilities from the tata_bs_long
current_liabilities <- tata_bs_long[tata_bs_long$Items %in% c("STBor", "TP", "OCurrLiab", "STProv"), ]

# Sum Cash & Cash Equivalents and Current Liabilities for each year 2024 to 2020
cash_cash_equivalents_sum <- colSums(cash_cash_equivalents[, 2:6]) 
current_liabilities_sum <- colSums(current_liabilities[,2:6])  

# Calculate Cash Ratio
cash_ratio <- cash_cash_equivalents_sum / current_liabilities_sum

# Displaying the Cash Ratio
cash_ratio
##       2024       2023       2022       2021       2020 
## 0.18849923 0.05482389 0.09652311 0.16452133 0.13684920
#Create a data frame for plotting
cash_ratio_data <- data.frame(
  Year = as.numeric(names(cash_ratio)),  # Extract years from names
  cash_ratio = as.numeric(cash_ratio)  # Convert values to numeric
)

#Plot Cash Ratio
ggplot(cash_ratio_data, aes(x = Year, y = cash_ratio)) +
  geom_line(color = "yellow", linewidth = 1.5) +  # Use linewidth for line thickness
  geom_point(color = "darkviolet", size = 3.5) +     # Add points for each year
  labs(
    title = "Cash Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Cash Ratio"
  ) +
  scale_y_continuous(
    limits = c(0.04, 0.2), # Set y-axis limits
    breaks = seq(0.04, 0.2, by = 0.02), # Set the breaks on the y-axis
    labels = seq(0.04, 0.2, by = 0.02)  # Label the y-axis with values from 0.04 to 0.2
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

PROFITABILITY

TATA MOTORS FINANCIAL LEVERAGE RATIO

BY SHUSHAL

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Financial Leverage Ratio
#Financial Leverage Ratio = Total Assets/Total Equity
#First step --> Finding Assets

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
flr1_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="TangAst",])

flrp1_tata=ggplot(flr1_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Tangible Assets",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(9000, 21000),  # Set y-axis limits
    breaks = seq(9000, 21000, by = 3000),  # Set the breaks on the y-axis
    labels = seq(9, 21, by = 3), # Label the y-axis with values from 9 to 21
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
flr2_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="IntangAst",])

flrp2_tata=ggplot(flr2_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Tangible Assets",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1000, 7000),  # Set y-axis limits
    breaks = seq(1000, 7000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(1, 7, by = 1), # Label the y-axis with values from 1 to 7
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
flr3_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="CapWIP",])

flrp3_tata=ggplot(flr3_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Capital Work-in-Progress",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(400, 1900),  # Set y-axis limits
    breaks = seq(400, 1900, by = 300),  # Set the breaks on the y-axis
    labels = seq(4, 19, by = 3), # Label the y-axis with values from 4 to 19
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
flr4_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="IntangUdvpt",])

flrp4_tata=ggplot(flr4_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Intangible Assets under Development",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(400, 2900),  # Set y-axis limits
    breaks = seq(400, 2900, by = 500),  # Set the breaks on the y-axis
    labels = seq(4, 29, by = 5), # Label the y-axis with values from 4 to 29
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 5
flr5_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="FA",])

flrp5_tata=ggplot(flr5_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Fixed Assets",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(13000, 31000),  # Set y-axis limits
    breaks = seq(13000, 31000, by = 3000),  # Set the breaks on the y-axis
    labels = seq(13, 31, by = 3), # Label the y-axis with values from 13 to 31
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 6
flr6_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="NonCurInvst",])

flrp6_tata=ggplot(flr6_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Non-Current Investments",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(14000, 32000),  # Set y-axis limits
    breaks = seq(14000, 32000, by = 3000),  # Set the breaks on the y-axis
    labels = seq(14, 32, by = 3), # Label the y-axis with values from 14 to 32
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 7
flr7_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="DTA_Net",])

flrp7_tata=ggplot(flr7_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Deferred Tax Assets(Net)",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(0, 1800),  # Set y-axis limits
    breaks = seq(0, 1800, by = 300),  # Set the breaks on the y-axis
    labels = seq(0, 18, by = 3), # Label the y-axis with values from 0 to 18
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 8
flr8_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="LT_LoanAdv",])

flrp8_tata=ggplot(flr8_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Long-Term Loans & Advances",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(30, 150),  # Set y-axis limits
    breaks = seq(30, 150, by = 20),  # Set the breaks on the y-axis
    labels = seq(30, 150, by = 20), # Label the y-axis with values from 30 to 50
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 9
flr9_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="ONonCurAst",])

flrp9_tata=ggplot(flr9_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Other Non-Current Assets",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(3100, 4000),  # Set y-axis limits
    breaks = seq(3100, 4000, by = 300),  # Set the breaks on the y-axis
    labels = seq(31, 40, by = 3), # Label the y-axis with values from 31 to 40
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 10
flr10_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="CurInvst",])

flrp10_tata=ggplot(flr10_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Current Investments",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(600, 5400),  # Set y-axis limits
    breaks = seq(600, 5400, by = 600),  # Set the breaks on the y-axis
    labels = seq(6, 54, by = 6), # Label the y-axis with values from 6 to 54
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 11
flr11_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Inv",])

flrp11_tata=ggplot(flr11_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Inventories",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(2800, 4800),  # Set y-axis limits
    breaks = seq(2800, 4800, by = 400),  # Set the breaks on the y-axis
    labels = seq(28, 48, by = 4), # Label the y-axis with values from 28 to 48
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 12
flr12_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="TR",])

flrp12_tata=ggplot(flr12_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Trade Receivables",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1800, 3000),  # Set y-axis limits
    breaks = seq(1800, 3000, by = 200),  # Set the breaks on the y-axis
    labels = seq(18, 30, by = 2), # Label the y-axis with values from 18 to 30
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 13
flr13_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Cash_CE",])

flrp13_tata=ggplot(flr13_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Cash & Cash Equivalents",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1200, 5400),  # Set y-axis limits
    breaks = seq(1200, 5400, by = 600),  # Set the breaks on the y-axis
    labels = seq(12, 54, by = 6), # Label the y-axis with values from 12 to 54
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 14
flr14_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="ST_LoanAdv",])

flrp14_tata=ggplot(flr14_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Short-Term Loans & Advances",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(120, 240),  # Set y-axis limits
    breaks = seq(120, 240, by = 20),  # Set the breaks on the y-axis
    labels = seq(120, 240, by = 20), # Label the y-axis with values from 120 to 240
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 15
flr15_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="OCurrAst",])

flrp15_tata=ggplot(flr15_tata,aes(x=Year,y=Amount))+
  geom_point(col="hotpink",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkgrey",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Other Current Assets",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(1300, 3300),  # Set y-axis limits
    breaks = seq(1300, 3300, by = 200),  # Set the breaks on the y-axis
    labels = seq(13, 33, by = 2), # Label the y-axis with values from 13 to 33
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Financial Leverage Ratio = Total Assets/Total Equity

#Second step --> Finding Total Equity

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 16
flr16_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="EqShCap",])

flrp16_tata=ggplot(flr16_tata, aes(x = Year, y = Amount)) +
  geom_point(col = "hotpink", size = 5) +
  geom_line(aes(group = 1), col = "darkgrey", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in Crores",
    title = "Equity Share Capital",
    caption = "Cleaned by Team",
    subtitle = "TATA Motors Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(710, 780),            # Set y-axis limits
    breaks = seq(710, 780, by = 10), # Set the breaks on the y-axis
    labels = seq(710, 780, by = 10)     # Label the y-axis with values from 710 to 780
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 17
flr17_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Res_Surp",])

flrp17_tata=ggplot(flr17_tata, aes(x = Year, y = Amount)) +
  geom_point(col = "hotpink", size = 5) +
  geom_line(aes(group = 1), col = "darkgrey", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in 000's(cr.)",
    title = "Reserves & Surplus",
    caption = "Cleaned by Team",
    subtitle = "TATA Motors Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(15000, 31000),            # Set y-axis limits
    breaks = seq(15000, 31000, by = 2000), # Set the breaks on the y-axis
    labels = seq(15, 31, by = 2)     # Label the y-axis with values from 15 to 31
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 18
flr18_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="EqShApMony",])

flrp18_tata=ggplot(flr18_tata, aes(x = Year, y = Amount)) +
  geom_point(col = "hotpink", size = 5) +
  geom_line(aes(group = 1), col = "darkgrey", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in Crores",
    title = "Equity Share Application Money",
    caption = "Cleaned by Team",
    subtitle = "TATA Motors Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(0, 7),            # Set y-axis limits
    breaks = seq(0, 7, by = 1),  # Set the breaks on the y-axis
    labels = seq(0, 7, by = 1)   # Label the y-axis with values from 0 to 7
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Total Equity

grid.arrange(
  flrp16_tata, flrp18_tata,  # First row: Two charts
  flrp17_tata,            # Second row: One wide chart
  nrow = 2,            # 2 rows
  ncol = 2,            # 2 columns
  layout_matrix = rbind(c(1, 2),  # Top two plots
                        c(3, 3)), # Bottom plot spans full width
  heights = c(1.5, 1.75)  # Give more space to bottom chart
)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

tata_bs_long<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
# Inspect the data structure
head(tata_bs_long)
Items 2024 2023 2022 2021 2020 Category
EqShCap 766.50 766.02 765.88 765.81 719.54 SholderFunds
Res_Surp 29374.83 21701.37 19171.88 18290.16 16800.61 SholderFunds
EqShApMony 1.72 2.46 6.39 0.00 0.00 SholderFunds
LTBor 5235.67 10445.70 14102.74 16326.77 14776.51 NonCurLiab
DTL_Net 49.78 51.16 173.72 266.50 198.59 NonCurLiab
Other_LTB 1392.16 1411.78 1212.34 1786.93 1646.56 NonCurLiab
# Filtering Total Asset from the tata_bs_long
total_assets <- tata_bs_long[tata_bs_long$Items %in% c("TangAst", "IntangAst", "CapWIP", "IntangUdvpt", "FA", "NonCurInvst", "DTA_Net", "LT_LoanAdv",
                                                       "ONonCurAst", "CurInvst", "Inv", "TR", "Cash_CE", "ST_LoanAdv", "OCurrAst"), ]

# Filtering Total Equity from the tata_bs_long
total_equity <- tata_bs_long[tata_bs_long$Items %in% c("EqShCap", "Res_Surp", "EqShApMony"), ]

# Sum Total Asset and Total Equity for each year 2024 to 2020
total_assets_sum <- colSums(total_assets[, 2:6]) 
total_equity_sum <- colSums(total_equity[,2:6])  

# Calculate Financial Leverage Ratio
financial_leverage_ratio <- total_assets_sum / total_equity_sum

# Displaying the Financial Leverage Ratio
financial_leverage_ratio
##     2024     2023     2022     2021     2020 
## 2.709140 3.444529 3.983267 4.958510 5.267800
#Create a data frame for plotting
financial_leverage_ratio_data <- data.frame(
  Year = as.numeric(names(financial_leverage_ratio)),  # Extract years from names
  financial_leverage_ratio = as.numeric(financial_leverage_ratio)  # Convert values to numeric
)

# Plot Financial Leverage Ratio
ggplot(financial_leverage_ratio_data, aes(x = Year, y = financial_leverage_ratio)) +
  geom_line(color = "darkorange", linewidth = 1.5) +  # Use linewidth for line thickness
  geom_point(color = "black", size = 3.5) +     # Add points for each year
  labs(
    title = "Financial Leverage Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Financial Leverage Ratio"
  ) +
  scale_y_continuous(
    limits = c(2.5, 5.5), # Set y-axis limits
    breaks = seq(2.5, 5.5, by = 0.5), # Set the breaks on the y-axis
    labels = seq(2.5, 5.5, by = 0.5)  # Label the y-axis with values from 2.5 to 5.5
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Load necessary library
library(ggplot2)

# Creating the financial_leverage_ratio_data data frame
financial_leverage_ratio_data <- data.frame(
  Year = c(2020, 2021, 2022, 2023, 2024),
  Financial_Leverage_Ratio = c(5.1, 4.8, 3.9, 3.2, 2.7)  # Example values (replace with actual data)
)

# Plot: Financial Leverage Ratio Bar Chart
ggplot(financial_leverage_ratio_data, aes(x = factor(Year), y = Financial_Leverage_Ratio, fill = Year)) +
  geom_bar(stat = "identity", width = 0.6, show.legend = FALSE) +  # Bar plot
  scale_fill_gradient(low = "red", high = "blue") +  # Gradient fill for visual effect
  labs(
    title = "Financial Leverage Ratio Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Financial Leverage Ratio"
  ) +
  scale_y_continuous(
    limits = c(0, 5.5),  # Adjust y-axis limits based on data
    breaks = seq(0, 5.5, by = 0.5)  # Set breaks for better readability
  ) +
  geom_text(aes(label = round(Financial_Leverage_Ratio, 2)), 
            vjust = -0.5, size = 5) +  # Labels on bars
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

PROFITABILITY

TATA MOTORS GROSS PROFIT MARGIN RATIO

BY RAHUL

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
tata_pl<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
tata_pl<-as.data.frame(tata_pl)

#clean the column names
colnames(tata_pl)<-make.names(colnames(tata_pl))
colnames(tata_pl)<-trimws(colnames(tata_pl))

#reshaping the data to long format
tata_pl_long<-reshape(tata_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_pl_long)<-NULL

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Gross Profit Margin
#Gross Profit Margin = [Gross (Profit/Loss)/Revenue]*100

#Gross Profit/Loss = Operating Revenue - Operating Expense

#Operating Revenue = Revenue from Operations + Other Operating Revenue
#Operating Expense = Cost of Goods Sold + Purchase of Stock-in-Trade + Operating and Direct Expenses + Changes in Inventories of FG, WIP, SIT)

#First Step --> Operating Revenue

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
gpm1_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="Revenue_Op",])

gpmp1_tata=ggplot(gpm1_tata,aes(x=Year,y=Amount))+
  geom_point(col="brown",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="yellow",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Revenue From Operations",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(25000, 75000),  # Set y-axis limits
    breaks = seq(25000, 75000, by = 10000),  # Set the breaks on the y-axis
    labels = seq(25, 75, by = 10),# Label the y-axis with values from 25 to 75
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
gpm2_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="OtherOpRev",])

gpmp2_tata=ggplot(gpm2_tata,aes(x=Year,y=Amount))+
  geom_point(col="brown",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="yellow",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Other Operating Revenue",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(350, 600),  # Set y-axis limits
    breaks = seq(350, 600, by = 50),  # Set the breaks on the y-axis
    labels = seq(350, 600, by = 50),# Label the y-axis with values from 350 to 600
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Combind Plot

#Balanced Layout - Total Operating Revenue

grid.arrange(gpmp1_tata,gpmp2_tata,nrow=2,ncol=1)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Gross Profit/Loss = Operating Revenue - Operating Expense

#Operating Revenue = Revenue from Operations + Other Operating Revenue
#Operating Expense = Cost of Goods Sold + Purchase of Stock-in-Trade + Operating and Direct Expenses + Changes in Inventories of FG, WIP, SIT)

#Second Step --> Operating Expense

#-----------------------------------------------------------------------------------------------------------------------------------------------------


#Read the file for Profit and loss
tata_pl<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
tata_pl<-as.data.frame(tata_pl)

#clean the column names
colnames(tata_pl)<-make.names(colnames(tata_pl))
colnames(tata_pl)<-trimws(colnames(tata_pl))

#reshaping the data to long format
tata_pl_long<-reshape(tata_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
gpm3_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="COGS",])

gpmp3_tata=ggplot(gpm3_tata,aes(x=Year,y=Amount))+
  geom_point(col="brown",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="yellow",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Cost of Goods Sold",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(18000, 46000),              # Set y-axis limits
    breaks = seq(18000, 46000, by = 4000), # Set the breaks on the y-axis 
    labels = seq(18, 46, by = 4)           # Label the y-axis with values from 18 to 46
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
gpm4_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="PurOfSIT",])

gpmp4_tata=ggplot(gpm4_tata,aes(x=Year,y=Amount))+
  geom_point(col="brown",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="yellow",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Purchase of Stock-in-Trade",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(3000, 8000),               # Set y-axis limits
    breaks = seq(3000, 8000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(3, 8, by = 1),           # Label the y-axis with values from 3 to 8
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 5
gpm5_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="Op_DirExp",])

gpmp5_tata=ggplot(gpm5_tata,aes(x=Year,y=Amount))+
  geom_point(col="brown",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="yellow",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Operating & Direct Expenses",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(300, 1200),  # Set y-axis limits
    breaks = seq(300, 1200, by = 300),  # Set the breaks on the y-axis
    labels = seq(3, 12, by = 3)  # Label the y-axis with values from 3 to 12
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )   

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 6
gpm6_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="Chg_InvFgWipSIT",])

gpmp6_tata=ggplot(gpm6_tata,aes(x=Year,y=Amount))+
  geom_point(col="brown",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="yellow",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Changes in Inventories of FG, WIP & SIT",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(-650, 750),  # Set y-axis limits
    breaks = seq(-650, 750, by = 200),  # Set the breaks on the y-axis
    labels = seq(-65, 75, by = 20 )  # Label the y-axis with values from 3 to 15
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )   

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Total Operating Expense

grid.arrange(gpmp3_tata,gpmp4_tata,gpmp5_tata,gpmp6_tata,nrow=2,ncol=2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

op_rev1<-gpm1_tata
op_rev2<-gpm2_tata
print(op_rev1)
##          Items Category Year   Amount id
## 1   Revenue_Op  Incomes 2024 72745.92  1
## 27  Revenue_Op  Incomes 2023 65298.84  1
## 53  Revenue_Op  Incomes 2022 46880.97  1
## 79  Revenue_Op  Incomes 2021 29769.07  1
## 105 Revenue_Op  Incomes 2020 43485.76  1
print(op_rev2)
##          Items Category Year Amount id
## 2   OtherOpRev  Incomes 2024 557.16  2
## 28  OtherOpRev  Incomes 2023 458.49  2
## 54  OtherOpRev  Incomes 2022 382.71  2
## 80  OtherOpRev  Incomes 2021 405.96  2
## 106 OtherOpRev  Incomes 2020 442.41  2
# Creating the data frames for op_rev1 and op_rev2
op_rev1_data <- data.frame(
  Items = rep("Revenue_Op", 5),
  Category = rep("Incomes", 5),
  Year = c(2024, 2023, 2022, 2021, 2020),
  Amount = c(72745.92, 65298.84, 46880.97, 29769.07, 43485.76),
  id = rep(1, 5)
)

op_rev2_data <- data.frame(
  Items = rep("OtherOpRev", 5),
  Category = rep("Incomes", 5),
  Year = c(2024, 2023, 2022, 2021, 2020),
  Amount = c(557.16, 458.49, 382.71, 405.96, 442.41),
  id = rep(2, 5)
)

# Merging op_rev1 and op_rev2 by Year
operating_revenue <- merge(op_rev1[, c("Year", "Amount")], op_rev2[, c("Year", "Amount")], by = "Year", suffixes = c("_op_rev1", "_op_rev2"))

# Creating the new Amount column by summing the Amount columns from both data frames
operating_revenue$Amount <- operating_revenue$Amount_op_rev1 + operating_revenue$Amount_op_rev2

# Selecting only relevant columns (Year and Amount) for the final data frame
operating_revenue <- operating_revenue[, c("Year", "Amount")]

# Print the resulting operating_revenue data frame
print(operating_revenue)
##   Year   Amount
## 1 2020 43928.17
## 2 2021 30175.03
## 3 2022 47263.68
## 4 2023 65757.33
## 5 2024 73303.08
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

op_exp1<-gpm3_tata
op_exp2<-gpm4_tata
op_exp3<-gpm5_tata
op_exp4<-gpm6_tata 

print(op_exp1)
##     Items Category Year   Amount id
## 4    COGS Expenses 2024 45025.05  4
## 30   COGS Expenses 2023 42226.81  4
## 56   COGS Expenses 2022 31693.11  4
## 82   COGS Expenses 2021 19050.74  4
## 108  COGS Expenses 2020 26171.85  4
print(op_exp2)
##        Items Category Year  Amount id
## 5   PurOfSIT Expenses 2024 7764.19  5
## 31  PurOfSIT Expenses 2023 6561.32  5
## 57  PurOfSIT Expenses 2022 5030.00  5
## 83  PurOfSIT Expenses 2021 3156.80  5
## 109 PurOfSIT Expenses 2020 5679.98  5
print(op_exp3)
##         Items Category Year  Amount id
## 6   Op_DirExp Expenses 2024 1104.79  6
## 32  Op_DirExp Expenses 2023  899.06  6
## 58  Op_DirExp Expenses 2022  593.90  6
## 84  Op_DirExp Expenses 2021  348.71  6
## 110 Op_DirExp Expenses 2020  830.24  6
print(op_exp4)
##               Items Category Year  Amount id
## 7   Chg_InvFgWipSIT Expenses 2024 -600.44  7
## 33  Chg_InvFgWipSIT Expenses 2023  484.69  7
## 59  Chg_InvFgWipSIT Expenses 2022 -403.87  7
## 85  Chg_InvFgWipSIT Expenses 2021 -609.55  7
## 111 Chg_InvFgWipSIT Expenses 2020  722.68  7
# Extracting 'Year' and 'Amount' from each data frame and assigning appropriate column names
op_exp1_data <- op_exp1[, c("Year", "Amount")]
colnames(op_exp1_data) <- c("Year", "Amount_op_exp1")

op_exp2_data <- op_exp2[, c("Year", "Amount")]
colnames(op_exp2_data) <- c("Year", "Amount_op_exp2")

op_exp3_data <- op_exp3[, c("Year", "Amount")]
colnames(op_exp3_data) <- c("Year", "Amount_op_exp3")

op_exp4_data <- op_exp4[, c("Year", "Amount")]
colnames(op_exp4_data) <- c("Year", "Amount_op_exp4")

#Merging the first two data frames
operating_expense <- merge(op_exp1[, c("Year", "Amount")], 
                           op_exp2[, c("Year", "Amount")], 
                           by = "Year", 
                           suffixes = c("_op_exp1", "_op_exp2"))

# Merging the result with the third data frame
operating_expense <- merge(operating_expense, 
                           op_exp3[, c("Year", "Amount")], 
                           by = "Year")

# Merging the result with the fourth data frame
operating_expense <- merge(operating_expense, 
                           op_exp4[, c("Year", "Amount")], 
                           by = "Year")

# Renaming columns 
colnames(operating_expense) <- c("Year", "Amount_op_exp1", "Amount_op_exp2", "Amount_op_exp3", "Amount_op_exp4")

# Print the final merged data frame
print(operating_expense)
##   Year Amount_op_exp1 Amount_op_exp2 Amount_op_exp3 Amount_op_exp4
## 1 2020       26171.85        5679.98         830.24         722.68
## 2 2021       19050.74        3156.80         348.71        -609.55
## 3 2022       31693.11        5030.00         593.90        -403.87
## 4 2023       42226.81        6561.32         899.06         484.69
## 5 2024       45025.05        7764.19        1104.79        -600.44
# Summing the amounts across each row for the respective columns
operating_expense$Amount_Sum <- rowSums(operating_expense[, c("Amount_op_exp1", "Amount_op_exp2", "Amount_op_exp3", "Amount_op_exp4")], na.rm = TRUE)

# Creating the final data frame with Year and the sum of Amounts
operating_expense <- operating_expense[, c("Year", "Amount_Sum")]

# Printing the final data frame
print(operating_expense)
##   Year Amount_Sum
## 1 2020   33404.75
## 2 2021   21946.70
## 3 2022   36913.14
## 4 2023   50171.88
## 5 2024   53293.59
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

# Merging the operating_revenue and operating_expense data frames by Year
gross_profit <- merge(operating_revenue, operating_expense, by = "Year")

# Calculating the Gross Profit  for each year
gross_profit$Amount_Gross_Profit <- gross_profit$Amount - gross_profit$Amount_Sum

# Selecting the relevant columns (Year and Gross Profit )
gross_profit <- gross_profit[, c("Year", "Amount_Gross_Profit")]

# Printing the final gross profit  data frame
print(gross_profit)
##   Year Amount_Gross_Profit
## 1 2020            10523.42
## 2 2021             8228.33
## 3 2022            10350.54
## 4 2023            15585.45
## 5 2024            20009.49
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Loading package
library(ggplot2)

# Create the line plot
ggplot(gross_profit, aes(x = as.numeric(Year), y = Amount_Gross_Profit)) +
  geom_line(color = "gold", size = 2) +
  geom_point(color = "black", size = 4) +   
  labs(title = "Gross Profit Over the Years", 
       x = "Year", 
       y = "Gross Profit") +
  theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

# Loading package
library(ggplot2)

# Assuming 'gross_profit_margin' data frame has 'Year' and 'Amount_Gross_Profit'
gross_profit <- data.frame(
  Year = c(2020, 2021, 2022, 2023, 2024),
  Amount_Gross_Profit = c(10456.92, 8180.33, 10350.54, 15585.45, 20009.49)
)

# Bar plot for Gross Profit Margin
ggplot(gross_profit, aes(x = factor(Year), 
                                y = Amount_Gross_Profit, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black") +  
  labs(title = "Gross Profit  (2020 - 2024)", x = "Year",
       y = "Gross Profit  (Amount)") +
  scale_fill_manual(values = c("2024" = "green", "2023" = "violet",
                               "2022" = "yellow", "2021" = "red", "2020" = "blue")) +
  geom_text(aes(label = round(Amount_Gross_Profit, 2)), vjust = -0.5, size = 4, color = "black") +  
  scale_y_continuous(
    limits = c(0, 25000), # Adjust y-axis limits according to the data range
    breaks = seq(0, 25000, by = 5000), # Set breaks on y-axis
    labels = seq(0, 25000, by = 5000),  # Label the y-axis with values from 0 to 25000
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
tata_pl<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
tata_pl<-as.data.frame(tata_pl)

#clean the column names
colnames(tata_pl)<-make.names(colnames(tata_pl))
colnames(tata_pl)<-trimws(colnames(tata_pl))

#reshaping the data to long format
tata_pl_long<-reshape(tata_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_pl_long)<-NULL

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#team 7
gpm7_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="Revenue_Op",])

gpmp7_tata=ggplot(gpm7_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkcyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 000's(cr.)",
       title="Revenue From Operations",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(25000, 75000),  # Set y-axis limits
    breaks = seq(25000, 75000, by = 10000),  # Set the breaks on the y-axis
    labels = seq(25, 75, by = 10),# Label the y-axis with values from 25 to 75
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )    

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#team 8
gpm8_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="OtherOpRev",])

gpmp8_tata=ggplot(gpm8_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkcyan",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="Other Operating Revenue",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(350, 600),  # Set y-axis limits
    breaks = seq(350, 600, by = 50),  # Set the breaks on the y-axis
    labels = seq(350, 600, by = 50),# Label the y-axis with values from 350 to 600
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  ) 

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#team 9
gpm9_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="OtherInc",])

gpmp9_tata=ggplot(gpm9_tata,aes(x=Year,y=Amount))+
  geom_point(col="darkorange",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkcyan",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Other Income",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(300, 1500),  # Set y-axis limits
    breaks = seq(300, 1500, by = 200),  # Set the breaks on the y-axis
    labels = seq(3, 15, by = 2), # Label the y-axis with values from 3 to 15
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )   

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Total Revenue

grid.arrange(
  gpmp9_tata, gpmp8_tata,  # First row: Two charts
  gpmp7_tata,            # Second row: One wide chart
  nrow = 2,            # 2 rows
  ncol = 2,            # 2 columns
  layout_matrix = rbind(c(1, 2),  # Top two plots
                        c(3, 3)), # Bottom plot spans full width
  heights = c(1.5, 1.75)  # Give more space to bottom chart
)

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Filtering Revenure from the tata_pl_long
revenue <- tata_pl_long[tata_pl_long$Items %in% c("Revenue_Op", "OtherOpRev", "OtherInc"), ]

#Sum Revenue and Net Profit/Loss for each year 2024 to 2020
revenue_total <- aggregate(Amount ~ Year, revenue, sum)

print(revenue_total)
##   Year   Amount
## 1 2020 45311.22
## 2 2021 30595.02
## 3 2022 47923.59
## 4 2023 66578.27
## 5 2024 74452.96
print(gross_profit)
##   Year Amount_Gross_Profit
## 1 2020            10456.92
## 2 2021             8180.33
## 3 2022            10350.54
## 4 2023            15585.45
## 5 2024            20009.49
#-------------------------------------------------------------------------------------------------------------------------------------------------------
# Creating the gross_profit_margin data frame
gross_profit_margin <- data.frame(
  Year = revenue_total$Year,
  Amount_Gross_Profit_Margin = round(gross_profit$Amount_Gross_Profit / revenue_total$Amount, 4) * 100  # Convert to percentage
)

# Printing the result
print(gross_profit_margin)
##   Year Amount_Gross_Profit_Margin
## 1 2020                      23.08
## 2 2021                      26.74
## 3 2022                      21.60
## 4 2023                      23.41
## 5 2024                      26.88
#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Loading the ggplot2 package
library(ggplot2)

# Creating the line plot
ggplot(gross_profit_margin, aes(x = Year, y = Amount_Gross_Profit_Margin, group = 1)) +
  geom_line(color = "blue", size = 2) +
  geom_point(color = "red", size = 3) +
  labs(title = "Gross Profit Margin Over the Years", 
       x = "Year", 
       y = "Gross Profit Margin (%)") +
  theme_minimal()

#------------------------------------------------------------------------------------------------------------------------------------------------------

# Loading package
library(ggplot2)

# Creating Data Frame for Gross Profit
gross_profit <- data.frame(
  Year = c(2020, 2021, 2022, 2023, 2024),
  Amount_Gross_Profit = c(10456.92, 8180.33, 10350.54, 15585.45, 20009.49)
)

# Bar plot for Gross Profit
ggplot(gross_profit, aes(x = factor(Year), 
                         y = Amount_Gross_Profit, fill = factor(Year))) +
  geom_bar(stat = "identity", color = "black", width = 0.6) +  
  labs(title = "Gross Profit (2020 - 2024)", 
       x = "Year", 
       y = "Gross Profit (Amount)") +
  scale_fill_manual(values = c("2024" = "steelblue",  
                               "2023" = "slategray",
                               "2022" = "darkorange",
                               "2021" = "forestgreen",
                               "2020" = "firebrick")) +
  geom_text(aes(label = round(Amount_Gross_Profit, 2)), 
            vjust = -0.5, size = 4, color = "black", fontface = "bold") +  
  scale_y_continuous(
    limits = c(0, 22000), # Adjusting y-axis limits 
    breaks = seq(0, 22000, by = 5000),  
    labels = scales::comma  
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 16),
    axis.title = element_text(size = 14),
    axis.text = element_text(size = 12),
    legend.position = "none"  
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Beyond the Basics: Advanced Financial Ratios 📊

OTHERS

TATA MOTORS CSR RATIO

BY HAREESH R

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
tata_pl<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
tata_pl<-as.data.frame(tata_pl)

#clean the column names
colnames(tata_pl)<-make.names(colnames(tata_pl))
colnames(tata_pl)<-trimws(colnames(tata_pl))

#reshaping the data to long format
tata_pl_long<-reshape(tata_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for CSR Expenditure
tata_csr<-read_excel("E:/finalproject/TataMotors_CSR.xlsx")
tata_csr<-as.data.frame(tata_csr)

#clean the column names
colnames(tata_csr)<-make.names(colnames(tata_csr))
colnames(tata_csr)<-trimws(colnames(tata_csr))

#reshaping the data to long format
tata_csr_long<-reshape(tata_csr,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_csr_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding CSR Ratio
#CSR Ratio = [CSR Expenditure/Net Profit(Loss)]*100
#First step --> CSR Expenditure

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
csr1_tata=as.data.frame(tata_csr_long[tata_csr_long$Items=="CSR_Spent",])

csrp1_tata=ggplot(csr1_tata,aes(x=Year,y=Amount))+
  geom_point(col="black",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="violet",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="CSR Expenditure",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(20, 25),  # Set y-axis limits
    breaks = seq(20, 25, by = 1),  # Set the breaks on the y-axis
    labels = seq(20, 25, by = 1), # Label the y-axis with values from 19 to 25
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#CSR Ratio = [CSR Expenditure/Net Profit(Loss)]*100

#Second step --> Finding Net Profit or Loss

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
csr2_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="Net_PorL",])

csrp2_tata=ggplot(csr2_tata,aes(x=Year,y=Amount))+
  geom_point(col="black",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="violet",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Net Profit or Loss",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(min(csr2_tata$Amount, na.rm = TRUE), max(csr2_tata$Amount, na.rm = TRUE)),
    breaks = seq(-8000, 8500, by = 1500),  
    labels = seq(-80, 85, by = 15)
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

tata_pl_long<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
#Inspect the data structure
head(tata_pl_long)
Items 2024 2023 2022 2021 2020 Category
Revenue_Op 72745.92 65298.84 46880.97 29769.07 43485.76 Incomes
OtherOpRev 557.16 458.49 382.71 405.96 442.41 Incomes
OtherInc 1149.88 820.94 659.91 419.99 1383.05 Incomes
COGS 45025.05 42226.81 31693.11 19050.74 26171.85 Expenses
PurOfSIT 7764.19 6561.32 5030.00 3156.80 5679.98 Expenses
Op_DirExp 1104.79 899.06 593.90 348.71 830.24 Expenses
tata_csr_long<-read_excel("E:/finalproject/TataMotors_CSR.xlsx")
#Inspect the data structure
head(tata_csr_long)
Items 2024 2023 2022 2021 2020 Category
Average_NpNl -1780.60 -4141.67 -2542.0 -2106.00 -600.07 Sec135_5
2_Percentage 0.00 0.00 0.0 0.00 0.00 Min_Req
SetOff 0.00 0.00 0.0 0.00 0.00 Surplus_BF
Obligation 0.00 0.00 0.0 0.00 0.00 Actual_Req
CSR_Spent 21.59 20.81 23.7 23.99 22.91 CSR
#Filtering CSR Expenditure from tata_csr_long
CSR_Expenditure <- csr1_tata
#reset row names
row.names(CSR_Expenditure)<-NULL

#Filtering Net Profit or Loss from the tata_pl_long
Net_Profit_Loss <- csr2_tata
#reset row names
row.names(Net_Profit_Loss)<-NULL

#Sum CSR Expenditure and Net Profit or Loss for each year 2024 to 2020
CSR_Expenditure_total <- aggregate(Amount ~ Year, CSR_Expenditure, sum)
Net_Profit_Loss_total <- aggregate(Amount ~ Year, Net_Profit_Loss, sum)

print(CSR_Expenditure_total)
##   Year Amount
## 1 2020  22.91
## 2 2021  23.99
## 3 2022  23.70
## 4 2023  20.81
## 5 2024  21.59
print(Net_Profit_Loss_total)
##   Year   Amount
## 1 2020 -7289.63
## 2 2021 -2395.44
## 3 2022 -1390.86
## 4 2023  2728.13
## 5 2024  7902.08
#Calculate CSR Ratio
#Convert Year to numeric
#Ensure Amount to numeric
CSR_Expenditure_total$Amount <- as.numeric(CSR_Expenditure_total$Amount)
Net_Profit_Loss_total$Amount <- as.numeric(Net_Profit_Loss_total$Amount)

#Compute CSR Ratio for each year
CSR_ratio <- (CSR_Expenditure_total$Amount / Net_Profit_Loss_total$Amount) * 100

# Displaying the CSR Ratio
CSR_ratio
## [1] -0.3142821 -1.0014862 -1.7039817  0.7627936  0.2732192
names(CSR_ratio) <- c(2020, 2021, 2022, 2023, 2024)  # Adjusting based on actual years

#Create a data frame for plotting
CSR_ratio_data <- data.frame(
  Year = as.numeric(names(CSR_ratio)),  # Extract years from names
  CSR_ratio = as.numeric(CSR_ratio)  # Convert values to numeric
)

# Plot CSR Ratio
ggplot(CSR_ratio_data, aes(x = Year, y = CSR_ratio)) +
  geom_line(color = "green", linewidth = 1.5) +  # Use linewidth for line thickness
  geom_point(color = "darkorange", size = 3.5) +     # Add points for each year
  labs(
    title = "CSR Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "CSR Ratio"
  ) +
  scale_y_continuous(
    limits = c(-2, 1), # Set y-axis limits
    breaks = seq(-2, 1, by = 0.5), # Set the breaks on the y-axis
    labels = seq(-2, 1, by = 0.5)  # Label the y-axis with values from -2 to 1
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load necessary library
library(ggplot2)

# Creating the CSR_ratio_data data frame
CSR_ratio_data <- data.frame(
  Year = c(2020, 2021, 2022, 2023, 2024),
  CSR_Ratio = c(-1.5, -0.8, -0.3, 0.2, 0.7)  
)

# Plot: CSR Ratio Bar Chart
ggplot(CSR_ratio_data, aes(x = factor(Year), y = CSR_Ratio, fill = CSR_Ratio > 0)) +
  geom_bar(stat = "identity", width = 0.6, show.legend = FALSE) +       
  scale_fill_manual(values = c("red", "green")) +        #Giving green colour for positive valuhe and red colour for negaative value    
  labs(
    title = "CSR Ratio for Tata Motors (2020–2024)",
    x = "Year",
    y = "CSR Ratio"
  ) +
  scale_y_continuous(
    limits = c(-1.7, 0.9),            #Setting y-axis limits
    breaks = seq(-1.7, 0.9, by = 0.2) #Setting breaks on y-axis
  ) +
  geom_text(aes(label = round(CSR_Ratio, 2)), 
            vjust = ifelse(CSR_ratio_data$CSR_Ratio > 0, -0.5, 1.5), 
            size = 5) +  
  theme_minimal() +
  geom_hline(yintercept = 0, linewidth = 1.5, color = "black") + #Highlighting the x-axis line, i.e. y=0 line
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

OTHERS

MAHINDRA & MAHINDRA LTD CSR RATIO

BY HAREESH R

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
mahindra_pl<-read_excel("E:/finalproject/Mahindra_PL_recleaned.xlsx")
mahindra_pl<-as.data.frame(mahindra_pl)

#clean the column names
colnames(mahindra_pl)<-make.names(colnames(mahindra_pl))
colnames(mahindra_pl)<-trimws(colnames(mahindra_pl))

#reshaping the data to long format
mahindra_pl_long<-reshape(mahindra_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(mahindra_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for CSR Expenditure
mahindra_csr<-read_excel("E:/finalproject/Mahindra_CSR.xlsx")
mahindra_csr<-as.data.frame(mahindra_csr)

#clean the column names
colnames(mahindra_csr)<-make.names(colnames(mahindra_csr))
colnames(mahindra_csr)<-trimws(colnames(mahindra_csr))

#reshaping the data to long format
mahindra_csr_long<-reshape(mahindra_csr,
                       varying = c("X2024","X2023","X2022","X2021","X2020"),
                       v.names = "Amount",
                       timevar = "Year",
                       times = c("2024","2023","2022","2021","2020"),
                       direction = "long")

#reset row names
row.names(mahindra_csr_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding CSR Ratio
#CSR Ratio = [CSR Expenditure/Net Profit(Loss)]*100
#First step --> CSR Expenditure

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
csr1_mahindra=as.data.frame(mahindra_csr_long[mahindra_csr_long$Items=="CSR_Spent",])

csrp1_mahindra=ggplot(csr1_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="gold",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkblue",
            linewidth=2)+
  labs(x="Year",y="Amount in Crores",
       title="CSR Expenditure",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(85, 130),  # Set y-axis limits
    breaks = seq(85, 130, by = 15),  # Set the breaks on the y-axis
    labels = seq(85, 130, by = 15), # Label the y-axis with values from 85 to 130
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#CSR Ratio = [CSR Expenditure/Net Profit(Loss)]*100

#Second step --> Finding Net Profit or Loss

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 2
csr2_mahindra=as.data.frame(mahindra_pl_long[mahindra_pl_long$Items=="Net_PorL",])

csrp2_mahindra=ggplot(csr2_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="gold",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="darkblue",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Net Profit or Loss",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(0, 11000),  # Set y-axis limits
    breaks = seq(0, 11000, by = 1000),  # Set the breaks on the y-axis
    labels = seq(0, 110, by = 10), # Label the y-axis with values from 85 to 130
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

mahindra_pl_long<-read_excel("E:/finalproject/Mahindra_PL_recleaned.xlsx")
#Inspect the data structure
head(mahindra_pl_long)
Items 2024 2023 2022 2021 2020 Category
Revenue_Op 96895.57 83251.31 56336.39 44296.95 44897.93 Incomes
OtherOpRev 1867.85 1708.95 1109.58 744.03 589.85 Incomes
OtherInc 4141.16 2545.17 2075.90 1221.31 1667.81 Incomes
COGS 71553.40 62226.20 40506.15 25035.89 22873.74 Expenses
PurOfSIT 4027.48 3406.84 2374.82 6817.12 8349.36 Expenses
Op_DirExp 0.00 0.00 0.00 0.00 0.00 Expenses
mahindra_csr_long<-read_excel("E:/finalproject/Mahindra_CSR.xlsx")
#Inspect the data structure
head(mahindra_csr_long)
Items 2024 2023 2022 2021 2020 Category
Average_NpNl 5616.45 4593.39 4842.32 5627.86 5328.18 Sec135_5
2_Percentage 112.33 91.87 96.85 112.56 106.56 Min_Req
SetOff 0.00 0.00 0.00 -20.00 0.00 Surplus_BF
Obligation 112.33 91.87 96.85 92.56 106.56 Actual_Req
CSR_Spent 112.74 92.28 97.08 92.78 126.59 CSR
#Filtering CSR Expenditure from mahindra_csr_long
CSR_Expenditure_mahindra <- csr1_mahindra
#reset row names
row.names(CSR_Expenditure_mahindra)<-NULL

#Filtering Net Profit or Loss from the mahindra_pl_long
Net_Profit_Loss_mahindra <- csr2_mahindra
#reset row names
row.names(Net_Profit_Loss_mahindra)<-NULL

#Sum CSR Expenditure and Net Profit or Loss for each year 2024 to 2020
CSR_Expenditure_mahindra_total <- aggregate(Amount ~ Year, CSR_Expenditure_mahindra, sum)
Net_Profit_Loss_mahindra_total <- aggregate(Amount ~ Year, Net_Profit_Loss_mahindra, sum)

print(CSR_Expenditure_mahindra_total)
##   Year Amount
## 1 2020 126.59
## 2 2021  92.78
## 3 2022  97.08
## 4 2023  92.28
## 5 2024 112.74
print(Net_Profit_Loss_mahindra_total)
##   Year   Amount
## 1 2020  1330.55
## 2 2021   268.66
## 3 2022  4935.22
## 4 2023  6548.64
## 5 2024 10717.80
#Calculate CSR Ratio
#Convert Year to numeric
#Ensure Amount to numeric
CSR_Expenditure_mahindra_total$Amount <- as.numeric(CSR_Expenditure_mahindra_total$Amount)
Net_Profit_Loss_mahindra_total$Amount <- as.numeric(Net_Profit_Loss_mahindra_total$Amount)

#Compute CSR Ratio for each year
CSR_ratio_mahindra <- (CSR_Expenditure_mahindra_total$Amount / Net_Profit_Loss_mahindra_total$Amount) * 100

# Displaying the CSR Ratio
CSR_ratio_mahindra
## [1]  9.514111 34.534356  1.967086  1.409148  1.051895
names(CSR_ratio_mahindra) <- c(2020, 2021, 2022, 2023, 2024)  # Adjusting based on actual years

#Create a data frame for plotting
CSR_ratio_mahindra_data <- data.frame(
  Year = as.numeric(names(CSR_ratio_mahindra)),  # Extracting years from names
  CSR_ratio_mahindra = as.numeric(CSR_ratio_mahindra)  # Converting values to numeric
)

# Plot CSR Ratio
ggplot(CSR_ratio_mahindra_data, aes(x = Year, y = CSR_ratio_mahindra)) +
  geom_line(color = "darkorange", linewidth = 1.5) +  # Use linewidth for line thickness
  geom_point(color = "blue", size = 3.5) +     # Add points for each year
  labs(
    title = "CSR Trend for Mahindra & Mahindra Limited (2020–2024)",
    x = "Year",
    y = "CSR Ratio"
  ) +
  scale_y_continuous(
    limits = c(0, 36), # Set y-axis limits
    breaks = seq(0, 36, by = 4), # Set the breaks on the y-axis
    labels = seq(0, 36, by = 4)  # Label the y-axis with values from 0 to 34
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load necessary library
library(ggplot2)

# Creating the CSR_ratio_mahindra_data data frame
CSR_ratio_mahindra_data <- data.frame(
  Year = c(2020, 2021, 2022, 2023, 2024),
  CSR_ratio_mahindra = c(9.51, 34.53, 1.97, 1.41, 1.05)  
)

# Plot: CSR Ratio Bar Chart
ggplot(CSR_ratio_mahindra_data, aes(x = factor(Year), y = CSR_ratio_mahindra, fill = Year)) +
  geom_bar(stat = "identity", width = 0.6, show.legend = FALSE) +
  scale_fill_gradient(low = "green", high = "red") +  #For highlighting high to low values
  labs(
    title = "CSR Ratio Trend for Mahindra & Mahindra Limited (2020–2024)",
    x = "Year",
    y = "CSR Ratio"
  ) +
  scale_y_continuous(
    limits = c(0, 36),           # Adjusting y-axis limits
    breaks = seq(0, 36, by = 4)  # Setting breaks on y-axis
  ) +
  geom_text(aes(label = round(CSR_ratio_mahindra, 2)), 
            vjust = -0.5, 
            size = 5) +  
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load ggplot2 library
library(ggplot2)

# Create DF for CSR Ratio
CSR_data <- data.frame(
  Year = rep(c(2020, 2021, 2022, 2023, 2024), 2),
  Company = c(rep("Tata Motors", 5), rep("Mahindra & Mahindra", 5)),
  CSR_Ratio = c(-0.3143, -1.0015, -1.7040, 0.7628, 0.2732,  
                9.5141, 34.5344, 1.9671, 1.4091, 1.0519)  
)

# Bar Chart
ggplot(CSR_data, aes(x = factor(Year), y = CSR_Ratio, fill = Company)) +
  geom_bar(stat = "identity", position = "dodge", color = "black", linewidth = 1) +
  labs(title = "CSR Ratio Comparison: Tata Motors vs Mahindra & Mahindra", 
       subtitle = "(2020-2024)",
       x = "Year", 
       y = "CSR Ratio",
       caption = "Source: Financial Reports of Tata Motors & Mahindra & Mahindra") +
  scale_fill_manual(values = c("Tata Motors" = "steelblue",  
                               "Mahindra & Mahindra" = "darkorange")) +  
  geom_text(aes(label = round(CSR_Ratio, 2)), 
            position = position_dodge(width = 0.9), 
            vjust = ifelse(CSR_data$CSR_Ratio < 0, 1.5, -0.5),  
            size = 5, color = "black", fontface = "bold") +  
  scale_y_continuous(
    limits = c(-2, 40),  
    breaks = seq(-2, 40, by = 5)  
  ) + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 18, color = "black"),
    plot.subtitle = element_text(hjust = 0.5, size = 14, color = "gray40"),
    axis.title = element_text(size = 14, face = "bold"),
    axis.text = element_text(size = 12),
    legend.position = "top",
    legend.title = element_blank(),
    legend.text = element_text(size = 12, face = "bold"),
    panel.border = element_rect(color = "black", fill = NA, linewidth = 1.5)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

Conclusion:

Tata Motors has shown negative CSR ratios in earlier years, indicating low or negative CSR spending but improved in 2023 and 2024. In contrast, Mahindra & Mahindra has consistently invested in CSR, with a significant spike in 2021, reflecting a strong commitment to corporate social responsibility.

OTHERS

TATA MOTORS CASH FLOW RATIO

BY HAREESH R

#load the packages
library(readxl)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Cash Flow
tata_cf<-read_excel("E:/finalproject/TataMotors_CF.xlsx")
tata_cf<-as.data.frame(tata_cf)

#clean the column names
colnames(tata_cf)<-make.names(colnames(tata_cf))
colnames(tata_cf)<-trimws(colnames(tata_cf))

#reshaping the data to long format
tata_cf_long<-reshape(tata_cf,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_cf_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load necessary package
library(dplyr)

# Creating net_cash_op dataframe
net_cash_op <- tata_cf_long %>%
  filter(Items == "NetCfrmOpAct") %>%  # Filtering only NetCfrmOpAct rows
  group_by(Year) %>%  # Group by Year
  summarise(Total_NetCfrmOpAct = sum(Amount, na.rm = TRUE))  # Sum the amounts

print(net_cash_op)
## # A tibble: 5 × 2
##   Year  Total_NetCfrmOpAct
##   <chr>              <dbl>
## 1 2020              -1455.
## 2 2021               6680.
## 3 2022               5282.
## 4 2023               4775.
## 5 2024               8662.
# Create the net_cash_inv dataframe
net_cash_inv <- tata_cf_long %>%
  filter(Items == "NetCusd_frm_InvstAct") %>%  # Filtering only NetCusd_frm_InvstAct rows
  group_by(Year) %>%  # Group by Year
  summarise(Total_NetCusdFrmInvstAct = sum(Amount, na.rm = TRUE))  # Sum the amounts

print(net_cash_inv)
## # A tibble: 5 × 2
##   Year  Total_NetCusdFrmInvstAct
##   <chr>                    <dbl>
## 1 2020                    -4719.
## 2 2021                    -2991.
## 3 2022                    -3149.
## 4 2023                      923.
## 5 2024                     1488.
# Create the net_cash_fin dataframe
net_cash_fin <- tata_cf_long %>%
  filter(Items == "NetCusd_frm_FinAct") %>%  # Filter only NetCusd_frm_FinAct rows
  group_by(Year) %>%  # Group by Year
  summarise(Total_NetCusdFrmFinAct = sum(Amount, na.rm = TRUE))  # Sum the amounts

print(net_cash_fin)
## # A tibble: 5 × 2
##   Year  Total_NetCusdFrmFinAct
##   <chr>                  <dbl>
## 1 2020                   7749.
## 2 2021                  -3472.
## 3 2022                   -516.
## 4 2023                  -7021.
## 5 2024                  -7930.
#-----------------------------------------------------------------------------------------------------------------------------------------------------

#line plot for  Net Cash Flow (From/Used in) Operating Activities
ggplot(net_cash_op, aes(x = Year, y = Total_NetCfrmOpAct)) +
  geom_point(color = "black", size = 4) +
  geom_line(color = "blue", linewidth = 1.5, group = 1) +
  labs(
    title = "Net Cash Flow (From/Used in) Operating Activities",
    x = "Year",
    y = "Amount in 000's(in cr.)"
  ) +
  scale_y_continuous(
    limits = c(-2000, 9000),
    breaks = seq(-2000, 9000, by = 1000),
    labels = seq(-2, 9, by = 1)
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#line plot for Net Cash Flow (From/Used in) Investing Activities

ggplot(net_cash_inv, aes(x = Year, y = Total_NetCusdFrmInvstAct)) +
  geom_point(color = "black", size = 4) +
  geom_line(color = "green", linewidth = 1.2, group = 1) +
  labs(
    title = "Net Cash (From/Used in) Investing Activities",
    x = "Year",
    y = "Amount in 000's(in cr.) "
  ) +
  scale_y_continuous(
    limits = c(-5000, 2000),
    breaks = seq(-5000, 2000, by = 1000),
    labels = seq(-5, 2, by = 1)
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#line plot for Net Cash Flow (From/Used in) Financing Activities

ggplot(net_cash_fin, aes(x = Year, y = Total_NetCusdFrmFinAct)) +
  geom_point(color = "black", size = 4) +
  geom_line(color = "red", linewidth = 1.2, group = 1) +
  labs(
    title = "Net Cash (From/Used in) Financing Activities",
    x = "Year",
    y = "Amount 000's(in cr.)"
  ) +
  scale_y_continuous(
    limits = c(-8500, 8000),
    breaks = seq(-8500, 8000, by = 1500),
    labels = seq(-8.5, 8, by = 1.5)
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Bar plot for Net Cash from Operating Activities

ggplot(net_cash_op, aes(x = as.factor(Year), y = Total_NetCfrmOpAct, fill = as.factor(Year))) +
  geom_bar(stat = "identity", color = "black", width = 0.6) +
  geom_text(aes(label = round(Total_NetCfrmOpAct, 2), 
                vjust = ifelse(Total_NetCfrmOpAct >= 0, -0.3, 1.2)),  
            size = 5, fontface = "bold") +  
  labs(
    title = "Net Cash Flow (From/Used in) Operating Activities",
    x = "Year",
    y = "Amount in 000's(cr.)"
  ) +
  scale_y_continuous(limits = c(-2000, 9000),  # Adjusted limits
                     breaks = seq(-2000, 9000, by = 1000),
                     labels = seq(-2, 9, by = 1)
  ) +
  scale_fill_viridis_d(option = "cividis") +
  theme_minimal() +
  geom_hline(yintercept = 0, linewidth = 1.5, color = "red") +  # Bold red X-axis at y=0
  theme(
    legend.position = "none",
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10),
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Bar plot for Net Cash Used in Investing Activities
ggplot(net_cash_inv, aes(x = as.factor(Year), y = Total_NetCusdFrmInvstAct, fill = as.factor(Year))) +
  geom_bar(stat = "identity", color = "black", width = 0.6) +
  geom_text(aes(label = round(Total_NetCusdFrmInvstAct, 2), 
                vjust = ifelse(Total_NetCusdFrmInvstAct >= 0, -0.3, 1.2)),  
            size = 5, fontface = "bold") +  
  labs(
    title = "Net Cash Flow (From/Used in) Investing Activities",
    x = "Year",
    y = "Amount in 000's(cr.)"
  ) +
  scale_y_continuous(
    limits = c(-5500, 2500),
    breaks = seq(-5500, 2500, by = 1000),
    labels = seq(-5.5, 2.5, by = 1)
  ) +
  scale_fill_viridis_d(option = "plasma") +
  theme_minimal() +
  geom_hline(yintercept = 0, linewidth = 1.5, color = "red") +  # Bold red X-axis at y=0
  theme(
    legend.position = "none",
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10),
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Bar plot for Net Cash Used in Financing Activities

ggplot(net_cash_fin, aes(x = as.factor(Year), y = Total_NetCusdFrmFinAct, fill = as.factor(Year))) +
  geom_bar(stat = "identity", color = "black", width = 0.6) +
  geom_text(aes(label = round(Total_NetCusdFrmFinAct, 2), 
                vjust = ifelse(Total_NetCusdFrmFinAct >= 0, -0.3, 1.2)),  
            size = 5, fontface = "bold") +  
  labs(
    title = "Net Cash Flow (From/Used in) Financing Activities",
    x = "Year",
    y = "Amount in 000's(cr.)"
  ) +
  scale_y_continuous(
    limits = c(-8500, 8000),
    breaks = seq(-8500, 8000, by = 1500),
    labels = seq(-8.5, 8, by = 1.5)
  ) +
  scale_fill_viridis_d(option = "viridis") +
  theme_minimal() +
  geom_hline(yintercept = 0, linewidth = 1.5, color = "red") +  # Use linewidth instead of size
  theme(
    legend.position = "none",
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

OTHERS

MAHINDRA & MAHINDRA LTD CASH FLOW RATIO

BY HAREESH R

#load the packages
library(readxl)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Cash Flow
mahindra_cf<-read_excel("E:/finalproject/Mahindra_CF.xlsx")
mahindra_cf<-as.data.frame(mahindra_cf)

#clean the column names
colnames(mahindra_cf)<-make.names(colnames(mahindra_cf))
colnames(mahindra_cf)<-trimws(colnames(mahindra_cf))

#reshaping the data to long format
mahindra_cf_long<-reshape(mahindra_cf,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(mahindra_cf_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load necessary package
library(dplyr)

# Creating net_cash_op_mahindra dataframe
net_cash_op_mahindra <- mahindra_cf_long %>%
  filter(Items == "NetCfrmOpAct") %>%  # Filtering only NetCfrmOpAct rows
  group_by(Year) %>%  # Group by Year
  summarise(Total_NetCfrmOpAct = sum(Amount, na.rm = TRUE))  # Sum the amounts

print(net_cash_op_mahindra)
## # A tibble: 5 × 2
##   Year  Total_NetCfrmOpAct
##   <chr>              <dbl>
## 1 2020               3678.
## 2 2021               9120.
## 3 2022               7094.
## 4 2023               9129.
## 5 2024              11279.
# Create the net_cash_inv_mahindra dataframe
net_cash_inv_mahindra <- mahindra_cf_long %>%
  filter(Items == "NetCusd_frm_InvstAct") %>%  # Filtering only NetCusd_frm_InvstAct rows
  group_by(Year) %>%  # Group by Year
  summarise(Total_NetCusdFrmInvstAct = sum(Amount, na.rm = TRUE))  # Sum the amounts

print(net_cash_inv_mahindra)
## # A tibble: 5 × 2
##   Year  Total_NetCusdFrmInvstAct
##   <chr>                    <dbl>
## 1 2020                    -2576.
## 2 2021                   -14564.
## 3 2022                    -4359.
## 4 2023                    -4753.
## 5 2024                    -5183.
# Create the net_cash_fin_mahindra dataframe
net_cash_fin_mahindra <- mahindra_cf_long %>%
  filter(Items == "NetCusd_frm_FinAct") %>%  # Filter only NetCusd_frm_FinAct rows
  group_by(Year) %>%  # Group by Year
  summarise(Total_NetCusdFrmFinAct = sum(Amount, na.rm = TRUE))  # Sum the amounts

print(net_cash_fin_mahindra)
## # A tibble: 5 × 2
##   Year  Total_NetCusdFrmFinAct
##   <chr>                  <dbl>
## 1 2020                  -1015.
## 2 2021                   3860.
## 3 2022                  -2885.
## 4 2023                  -3784.
## 5 2024                  -5538.
#-----------------------------------------------------------------------------------------------------------------------------------------------------

#line plot for  Net Cash Flow from Operating Activities
ggplot(net_cash_op_mahindra, aes(x = Year, y = Total_NetCfrmOpAct)) +
  geom_point(color = "black", size = 4) +
  geom_line(color = "green", linewidth = 1.5, group = 1) +
  labs(
    title = "Net Cash Flow (From/Used in) Operating Activities",
    x = "Year",
    y = "Amount in 000's(in cr.)"
  ) +
  scale_y_continuous(
    limits = c(3000, 12000),
    breaks = seq(3000, 12000, by = 1000),
    labels = seq(3, 12, by = 1)
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#line plot for Net Cash Used in Investing Activities

ggplot(net_cash_inv_mahindra, aes(x = Year, y = Total_NetCusdFrmInvstAct)) +
  geom_point(color = "black", size = 4) +
  geom_line(color = "red", linewidth = 1.2, group = 1) +
  labs(
    title = "Net Cash (From/Used in) Investing Activities",
    x = "Year",
    y = "Amount in 000's(in cr.) "
  ) +
  scale_y_continuous(
    limits = c(-15000, -2000),
    breaks = seq(-15000, -2000, by = 1000),
    labels = seq(-15, -2, by = 1)
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#line plot for Net Cash Used in Financing Activities

ggplot(net_cash_fin_mahindra, aes(x = Year, y = Total_NetCusdFrmFinAct)) +
  geom_point(color = "black", size = 4) +
  geom_line(color = "blue", linewidth = 1.2, group = 1) +
  labs(
    title = "Net Cash (From/Used in) Financing Activities",
    x = "Year",
    y = "Amount 000's(in cr.)"
  ) +
  scale_y_continuous(
    limits = c(-6000, 4500),
    breaks = seq(-6000, 4500, by = 1500),
    labels = seq(-6, 4.5, by = 1.5)
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Bar plot for Net Cash from Operating Activities

ggplot(net_cash_op_mahindra, aes(x = as.factor(Year), y = Total_NetCfrmOpAct, fill = as.factor(Year))) +
  geom_bar(stat = "identity", color = "black", width = 0.6) +
  geom_text(aes(label = round(Total_NetCfrmOpAct, 2), 
                vjust = ifelse(Total_NetCfrmOpAct >= 0, -0.3, 1.2)),  
            size = 5, fontface = "bold") +  
  labs(
    title = "Net Cash from Operating Activities",
    x = "Year",
    y = "Amount in 000's(cr.)"
  ) +
  scale_y_continuous(limits = c(-1000, 12000),  # Adjusted limits
                     breaks = seq(-1000, 12000, by = 1000),
                     labels = seq(-1, 12, by = 1)
  ) +
  scale_fill_viridis_d(option = "cividis") +
  theme_minimal() +
  geom_hline(yintercept = 0, linewidth = 1.5, color = "red") +  # Bold red X-axis at y=0
  theme(
    legend.position = "none",
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10),
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Bar plot for Net Cash Used in Investing Activities
ggplot(net_cash_inv_mahindra, aes(x = as.factor(Year), y = Total_NetCusdFrmInvstAct, fill = as.factor(Year))) +
  geom_bar(stat = "identity", color = "black", width = 0.6) +
  geom_text(aes(label = round(Total_NetCusdFrmInvstAct, 2), 
                vjust = ifelse(Total_NetCusdFrmInvstAct >= 0, -0.3, 1.2)),  
            size = 5, fontface = "bold") +  
  labs(
    title = "Net Cash Used in Investing Activities",
    x = "Year",
    y = "Amount in 000's(cr.)"
  ) +
  scale_y_continuous(
    limits = c(-15500, 1000),
    breaks = seq(-15500, 1000, by = 1500),
    labels = seq(-15.5, 1, by = 1.5)
  ) +
  scale_fill_viridis_d(option = "plasma") +
  theme_minimal() +
  geom_hline(yintercept = 0, linewidth = 1.5, color = "red") +  # Bold red X-axis at y=0
  theme(
    legend.position = "none",
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10),
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Bar plot for Net Cash Used in Financing Activities

ggplot(net_cash_fin_mahindra, aes(x = as.factor(Year), y = Total_NetCusdFrmFinAct, fill = as.factor(Year))) +
  geom_bar(stat = "identity", color = "black", width = 0.6) +
  geom_text(aes(label = round(Total_NetCusdFrmFinAct, 2), 
                vjust = ifelse(Total_NetCusdFrmFinAct >= 0, -0.3, 1.2)),  
            size = 5, fontface = "bold") +  
  labs(
    title = "Net Cash Used in Financing Activities",
    x = "Year",
    y = "Amount in 000's(cr.)"
  ) +
  scale_y_continuous(
    limits = c(-6000, 4500),
    breaks = seq(-6000, 4500, by = 1500),
    labels = seq(-6, 4.5, by = 1.5)
  ) +
  scale_fill_viridis_d(option = "viridis") +
  theme_minimal() +
  geom_hline(yintercept = 0, linewidth = 1.5, color = "red") +  # Use linewidth instead of size
  theme(
    legend.position = "none",
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

OTHERS

TATA MOTORS DUPONT ANALYSIS

BY GOUTHAM S

#DuPont Analysis

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
tata_pl<-read_excel("E:/finalproject/TataMotors_PL_recleaned.xlsx")
tata_pl<-as.data.frame(tata_pl)

#clean the column names
colnames(tata_pl)<-make.names(colnames(tata_pl))
colnames(tata_pl)<-trimws(colnames(tata_pl))

#reshaping the data to long format
tata_pl_long<-reshape(tata_pl,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Return on Equity(ROE) using DuPont Analysis
#Return on Equity = Net Income(Profit)/Shareholders' Equity
#First Step --> Net Income(Profit)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
roe1_tata=as.data.frame(tata_pl_long[tata_pl_long$Items=="Net_PorL",])

roep1_tata=ggplot(roe1_tata,aes(x=Year,y=Amount))+
  geom_point(col="black",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="violet",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Net Profit or Loss for the Period",
       caption = "Cleaned by Team",
       subtitle="TATA Motors Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(min(roe1_tata$Amount, na.rm = TRUE), max(roe1_tata$Amount, na.rm = TRUE)),
    breaks = seq(-7500, 8500, by = 2000),  
    labels = seq(-75, 85, by = 20)
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Creating the data frame
roe1_tata <- data.frame(
  Items = rep("Net_PorL", 5),
  Category = rep("Net_PorL", 5),
  Year = c(2024, 2023, 2022, 2021, 2020),
  Amount = c(7902.08, 2728.13, -1390.86, -2395.44, -7289.63),
  id = rep(25, 5)
)

# Creating net_profit_loss_tata with only "Year" and "Amount" columns
net_profit_loss_tata <- roe1_tata[, c("Year", "Amount")]

# Displaying the dataframe
print(net_profit_loss_tata)
##   Year   Amount
## 1 2024  7902.08
## 2 2023  2728.13
## 3 2022 -1390.86
## 4 2021 -2395.44
## 5 2020 -7289.63
#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Load necessary library
library(ggplot2)

# Creating the net_profit data frame
net_profit_loss_tata_data <- data.frame(
  Year = c(2024, 2023, 2022, 2021, 2020),
  Amount = c(7902.08, 2728.13, -1390.86, -2395.44, -7289.63)    # Net profit values 
)

# Plot: Net Profit Bar Chart with Labels
ggplot(net_profit_loss_tata_data, aes(x = factor(Year), y = Amount, fill = Amount > 0)) +
  geom_bar(stat = "identity", width = 0.6, show.legend = FALSE) +  # Bar plot
  scale_fill_manual(values = c("red", "green")) +  # Red for negative, green for positive
  geom_text(aes(label = Amount), 
            vjust = ifelse(net_profit_loss_tata$Amount > 0, -0.5, 1.5),  # Positioning labels
            color = "black", 
            size = 4, 
            fontface = "bold") + 
  labs(
    title = "Net Profit Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Net Profit (in crores)"
  ) +
  theme_minimal() +
  geom_hline(yintercept = 0, linewidth = 1.5, color = "black") +  #Highlighting the x-axis line at y = 0
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Return on Equity(ROE) using DuPont Analysis
#Return on Equity = Net Income(Profit)/Shareholders' Equity
#Second Step ---> Shareholders' Equity 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
tata_bs<-read_excel("E:/finalproject/TataMotors_BS.xlsx")
tata_bs<-as.data.frame(tata_bs)

#clean the column names
colnames(tata_bs)<-make.names(colnames(tata_bs))
colnames(tata_bs)<-trimws(colnames(tata_bs))

#reshaping the data to long format
tata_bs_long<-reshape(tata_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(tata_bs_long)<-NULL

#----------------------------------------------------------------------------------------------------------------------------------------------------- 

#team 2
roe2_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="EqShCap",])

roep2_tata=ggplot(roe2_tata, aes(x = Year, y = Amount)) +
  geom_point(col = "black", size = 5) +
  geom_line(aes(group = 1), col = "violet", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in Crores",
    title = "Equity Share Capital",
    caption = "Cleaned by Team",
    subtitle = "TATA Motors Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(710, 780),            # Set y-axis limits
    breaks = seq(710, 780, by = 10), # Set the breaks on the y-axis
    labels = seq(710, 780, by = 10)  # Label the y-axis with values from 710 to 780
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
roe3_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="Res_Surp",])

roep3_tata=ggplot(roe3_tata, aes(x = Year, y = Amount)) +
  geom_point(col = "black", size = 5) +
  geom_line(aes(group = 1), col = "violet", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in 000's(cr.)",
    title = "Reserves & Surplus",
    caption = "Cleaned by Team",
    subtitle = "TATA Motors Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(15000, 31000),            # Set y-axis limits
    breaks = seq(15000, 31000, by = 2000), # Set the breaks on the y-axis
    labels = seq(15, 31, by = 2)     # Label the y-axis with values from 15 to 31
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
roe4_tata=as.data.frame(tata_bs_long[tata_bs_long$Items=="EqShApMony",])

roep4_tata=ggplot(roe4_tata, aes(x = Year, y = Amount)) +
  geom_point(col = "black", size = 5) +
  geom_line(aes(group = 1), col = "violet", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in Crores",
    title = "Equity Share Application Money",
    caption = "Cleaned by Team",
    subtitle = "TATA Motors Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(0, 7),            # Set y-axis limits
    breaks = seq(0, 7, by = 1),  # Set the breaks on the y-axis
    labels = seq(0, 7, by = 1)   # Label the y-axis with values from 0 to 7
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Total Shareholders' Funds

grid.arrange(
  roep2_tata, roep4_tata,  # First row: Two charts
  roep3_tata,            # Second row: One wide chart
  nrow = 2,            # 2 rows
  ncol = 2,            # 2 columns
  layout_matrix = rbind(c(1, 2),  # Top two plots
                        c(3, 3)), # Bottom plot spans full width
  heights = c(1.5, 1.75)  # Give more space to bottom chart
)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

shareholders_equity <-tata_bs_long[tata_bs_long$Items %in% c("EqShCap", "Res_Surp","EqShApMony"), ]

print(shareholders_equity)
##          Items     Category Year   Amount id
## 1      EqShCap SholderFunds 2024   766.50  1
## 2     Res_Surp SholderFunds 2024 29374.83  2
## 3   EqShApMony SholderFunds 2024     1.72  3
## 30     EqShCap SholderFunds 2023   766.02  1
## 31    Res_Surp SholderFunds 2023 21701.37  2
## 32  EqShApMony SholderFunds 2023     2.46  3
## 59     EqShCap SholderFunds 2022   765.88  1
## 60    Res_Surp SholderFunds 2022 19171.88  2
## 61  EqShApMony SholderFunds 2022     6.39  3
## 88     EqShCap SholderFunds 2021   765.81  1
## 89    Res_Surp SholderFunds 2021 18290.16  2
## 90  EqShApMony SholderFunds 2021     0.00  3
## 117    EqShCap SholderFunds 2020   719.54  1
## 118   Res_Surp SholderFunds 2020 16800.61  2
## 119 EqShApMony SholderFunds 2020     0.00  3
# Summing Shareholders' Equity by year
shareholders_equity_sum <- shareholders_equity %>%
  group_by(Year) %>%
  summarise(shareholders_equity = sum(Amount))

# Print the result
print(shareholders_equity_sum)
## # A tibble: 5 × 2
##   Year  shareholders_equity
##   <chr>               <dbl>
## 1 2020               17520.
## 2 2021               19056.
## 3 2022               19944.
## 4 2023               22470.
## 5 2024               30143.
#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load necessary library
library(ggplot2)

# Creating the shareholders_equity_sum data frame
shareholders_equity_sum_data <- data.frame(
  Year = c(2020, 2021, 2022, 2023, 2024),
  shareholders_equity_sum = c(17520, 19056, 19944, 22470, 30143) # Total Shareholders' Equity values
)

# Plotting Total Shareholders' Equity Trend
ggplot(shareholders_equity_sum_data, aes(x = Year, y = shareholders_equity_sum)) +
  geom_line(color = "green", linewidth = 1.5) +  
  geom_point(color = "darkorange", size = 3.5) +
  labs(
    title = "Total Shareholders' Equity for Tata Motors (2020–2024)",
    x = "Year",
    y = "Total Equity in 000's(cr.)"
  ) +
  scale_y_continuous(
    limits = c(16000, 32000),              # Setting y-axis limits
    breaks = seq(16000, 32000, by = 2000), # Setting the breaks on the y-axis
    labels = seq(16, 32, by = 2)           # Labeling the y-axis from 16 to 32
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load necessary library
library(ggplot2)

# Creating the shareholders_equity_sum data frame
shareholders_equity_sum_data <- data.frame(
  Year = c(2020, 2021, 2022, 2023, 2024),
  shareholders_equity_sum = c(17520, 19056, 19944, 22470, 30143) # Total Shareholders' Equity values
)

# Plotting Total Shareholders' Equity Bar Chart 
ggplot(shareholders_equity_sum_data, aes(x = factor(Year), y = shareholders_equity_sum, fill = Year)) +
  geom_bar(stat = "identity", width = 0.6, show.legend = FALSE) +  
  scale_fill_gradient(low = "red", high = "green") +  
  geom_text(aes(label = shareholders_equity_sum), 
            vjust = -0.5,          # Positioning labels above the bars
            color = "black", 
            size = 4, 
            fontface = "bold") + 
  scale_y_continuous(
    limits = c(0, 32000),                 # Setting y-axis limits
    breaks = seq(0, 32000, by = 4000),    # Setting breaks on y-axis
    labels = seq(0, 32, by = 4),          # Labeling the y-axis from 0 to 32 
  ) +
  labs(
    title = "Total Shareholders' Equity Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "Total Shareholders' Equity (in crores)"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

print(net_profit_loss_tata)
##   Year   Amount
## 1 2024  7902.08
## 2 2023  2728.13
## 3 2022 -1390.86
## 4 2021 -2395.44
## 5 2020 -7289.63
print(shareholders_equity_sum)
## # A tibble: 5 × 2
##   Year  shareholders_equity
##   <chr>               <dbl>
## 1 2020               17520.
## 2 2021               19056.
## 3 2022               19944.
## 4 2023               22470.
## 5 2024               30143.
# Creating the return_on_equity data frame
return_on_equity <- data.frame(
  Year = net_profit_loss_tata$Year,                                                # Taking the Year column from net_profit_loss_tata
  ROE = net_profit_loss_tata$Amount / shareholders_equity_sum$shareholders_equity  # Calculating ROE
)

# Printing the return_on_equity dataframe
print(return_on_equity)
##   Year         ROE
## 1 2024  0.45102810
## 2 2023  0.14316406
## 3 2022 -0.06973774
## 4 2021 -0.10660685
## 5 2020 -0.24183452
#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load necessary library
library(ggplot2)

# Creating the return_on_equity_data frame
return_on_equity_data <- data.frame(
  Year = c(2020, 2021, 2022, 2023, 2024),
  ROE = c(-0.2418, -0.1066, -0.0697, 0.1432, 0.4510)  # ROE values
)

# Plotting line chart
ggplot(return_on_equity_data, aes(x = Year, y = ROE)) +
  geom_line(color = "blue", linewidth = 1.5) +  # Line plot
  geom_point(color = "red", size = 3.5) +       # Points on the plot
  labs(
    title = "Return on Equity (ROE) Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "ROE"
  ) +
  scale_y_continuous(
    limits = c(-0.3, 0.5), # Adjust y-axis limits based on data
    breaks = seq(-0.3, 0.5, by = 0.1), # Set breaks for better readability
    labels = scales::label_percent(accuracy = 0.1) # Format labels as percentages
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load necessary library
library(ggplot2)

# Creating the return_on_equity_data frame
return_on_equity_data <- data.frame(
  Year = c(2020, 2021, 2022, 2023, 2024),
  ROE = c(-0.2418, -0.1066, -0.0697, 0.1432, 0.4510)  # ROE values
)

# Plotting Return on Equity Bar Chart
ggplot(return_on_equity_data, aes(x = factor(Year), y = ROE, fill = ROE > 0)) +
  geom_bar(stat = "identity", width = 0.6, show.legend = FALSE) +  
  scale_fill_manual(values = c("red", "green")) +  
  labs(
    title = "Return on Equity (ROE) Trend for Tata Motors (2020–2024)",
    x = "Year",
    y = "ROE"
  ) +
  scale_y_continuous(
    limits = c(-0.3, 0.5),                          # Adjusting y-axis limits
    breaks = seq(-0.3, 0.5, by = 0.1),              # Setting breaks 
    labels = scales::label_percent(accuracy = 0.1)  # Formatting labels as percentages
  ) +
  geom_text(aes(label = scales::percent(ROE, accuracy = 0.1)), 
            vjust = ifelse(return_on_equity_data$ROE > 0, -0.5, 1.5), size = 5) +  
  theme_minimal() +
  geom_hline(yintercept = 0, linewidth = 1.5, color = "black") +  #Highlighting the x-axis line at y = 0
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

OTHERS

MAHINDRA & MAHINDRA LTD DUPONT ANALYSIS

BY GOUTHAM S

#DuPont Analysis

#load the packages
library(readxl)
library(gridExtra)
library(ggplot2)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file for Profit and loss
mahindra_pl<-read_excel("E:/finalproject/Mahindra_PL_recleaned.xlsx")
mahindra_pl<-as.data.frame(mahindra_pl)

#clean the column names
colnames(mahindra_pl)<-make.names(colnames(mahindra_pl))
colnames(mahindra_pl)<-trimws(colnames(mahindra_pl))

#reshaping the data to long format
mahindra_pl_long<-reshape(mahindra_pl,
                          varying = c("X2024","X2023","X2022","X2021","X2020"),
                          v.names = "Amount",
                          timevar = "Year",
                          times = c("2024","2023","2022","2021","2020"),
                          direction = "long")

#reset row names
row.names(mahindra_pl_long)<-NULL

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Return on Equity(ROE) using DuPont Analysis
#Return on Equity = Net Income(Profit)/Shareholders' Equity
#First Step --> Net Income(Profit)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 1
roe1_mahindra=as.data.frame(mahindra_pl_long[mahindra_pl_long$Items=="Net_PorL",])

roep1_mahindra=ggplot(roe1_mahindra,aes(x=Year,y=Amount))+
  geom_point(col="black",size=5)+
  geom_line(aes(x=Year,Amount, group=1),
            col="yellow",
            linewidth=2)+
  labs(x="Year",y="Amount in 00's(cr.)",
       title="Net Profit or Loss for the Period",
       caption = "Cleaned by Team",
       subtitle="Mahindra & Mahindra Limited (2020 - 2024)")+
  scale_y_continuous(
    limits = c(min(npm1_mahindra$Amount, na.rm = TRUE), max(npm1_mahindra$Amount, na.rm = TRUE)),
    breaks = seq(0, 11000, by = 1000),  
    labels = seq(0, 110, by = 10)
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Creating the data frame
roe1_mahindra <- data.frame(
  Items = rep("Net_PorL", 5),
  Category = rep("Net_PorL", 5),
  Year = c(2024, 2023, 2022, 2021, 2020),
  Amount = c(10717.80, 6548.64, 4935.22, 268.66, 1330.55),
  id = rep(25, 5)
)

# Creating net_profit_loss_mahindra with only "Year" and "Amount" columns
net_profit_loss_mahindra <- roe1_mahindra[, c("Year", "Amount")]

# Displaying the dataframe
print(net_profit_loss_mahindra)
##   Year   Amount
## 1 2024 10717.80
## 2 2023  6548.64
## 3 2022  4935.22
## 4 2021   268.66
## 5 2020  1330.55
#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Loading necessary library
library(ggplot2)

# Creating the net_profit data frame
net_profit_loss_mahindra_data <- data.frame(
  Year = c(2024, 2023, 2022, 2021, 2020),
  Amount = c(10717.80, 6548.64, 4935.22, 268.66, 1330.55)    # Net profit values 
)

# Plotting Net Profit Bar Chart 
ggplot(net_profit_loss_mahindra_data, aes(x = factor(Year), y = Amount, fill = Amount > 0)) +
  geom_bar(stat = "identity", width = 0.6, show.legend = FALSE) +
  scale_fill_manual(values = c("violet")) +  
  geom_text(aes(label = Amount), 
            vjust = ifelse(net_profit_loss_mahindra$Amount > 0, -0.5, 1.5), 
            color = "black", 
            size = 4, 
            fontface = "bold") + 
  labs(
    title = "Net Profit Trend for Mahindra & Mahindra Limited(2020–2024)",
    x = "Year",
    y = "Net Profit in 000's (in cr.)"
  ) +
  scale_y_continuous(
    limits = c(0, 11000),              # Setting y-axis limits
    breaks = seq(0, 11000, by = 1000), # Setting the breaks on the y-axis
    labels = seq(0, 11, by = 1)           # Labeling the y-axis from 0 to 11
  )+
  theme_minimal() +
  geom_hline(yintercept = 0, linewidth = 1, color = "black") +  #Highlighting the x-axis line at y = 0
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Finding Return on Equity(ROE) using DuPont Analysis
#Return on Equity = Net Income(Profit)/Shareholders' Equity
#Second Step ---> Shareholders' Equity 

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#Read the file of Balance Sheet
mahindra_bs<-read_excel("E:/finalproject/Mahindra_BS.xlsx")
mahindra_bs<-as.data.frame(mahindra_bs)

#clean the column names
colnames(mahindra_bs)<-make.names(colnames(mahindra_bs))
colnames(mahindra_bs)<-trimws(colnames(mahindra_bs))

#reshaping the data to long format
mahindra_bs_long<-reshape(mahindra_bs,
                      varying = c("X2024","X2023","X2022","X2021","X2020"),
                      v.names = "Amount",
                      timevar = "Year",
                      times = c("2024","2023","2022","2021","2020"),
                      direction = "long")

#reset row names
row.names(mahindra_bs_long)<-NULL

#----------------------------------------------------------------------------------------------------------------------------------------------------- 

#team 2
roe2_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="EqShCap",])

roep2_mahindra=ggplot(roe2_mahindra, aes(x = Year, y = Amount)) +
  geom_point(col = "black", size = 5) +
  geom_line(aes(group = 1), col = "yellow", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in Crores",
    title = "Equity Share Capital",
    caption = "Cleaned by Team",
    subtitle = "Mahindra & Mahindra Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(596, 600),            # Set y-axis limits
    breaks = seq(596, 600, by = 1), # Set the breaks on the y-axis
    labels = seq(596, 600, by = 1)     # Label the y-axis with values from 596 to 600
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 3
roe3_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="Res_Surp",])

roep3_mahindra=ggplot(roe3_mahindra, aes(x = Year, y = Amount)) +
  geom_point(col = "black", size = 5) +
  geom_line(aes(group = 1), col = "yellow", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in 000's(cr.)",
    title = "Reserves & Surplus",
    caption = "Cleaned by Team",
    subtitle = "Mahindra & Mahindra Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(32000, 53000),              # Set y-axis limits
    breaks = seq(32000, 53000, by = 3000), # Set the breaks on the y-axis
    labels = seq(32, 53, by = 3)           # Label the y-axis with values from 32 to 53
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#team 4
roe4_mahindra=as.data.frame(mahindra_bs_long[mahindra_bs_long$Items=="EqShApMony",])

roep4_mahindra=ggplot(roe4_mahindra, aes(x = Year, y = Amount)) +
  geom_point(col = "black", size = 5) +
  geom_line(aes(group = 1), col = "yellow", linewidth = 2) +
  labs(
    x = "Year",
    y = "Amount in Crores",
    title = "Equity Share Application Money",
    caption = "Cleaned by Team",
    subtitle = "Mahindra & Mahindra Limited (2020 - 2024)"
  ) +
  scale_y_continuous(
    limits = c(215, 305),            # Set y-axis limits
    breaks = seq(215, 305, by = 10), # Set the breaks on the y-axis
    labels = seq(215, 305, by = 10)     # Label the y-axis with values from 215 to 305
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

#combined plot

#Balanced Layout - Total Shareholders' Funds

grid.arrange(
  roep2_mahindra, roep4_mahindra,  # First row: Two charts
  roep3_mahindra,            # Second row: One wide chart
  nrow = 2,            # 2 rows
  ncol = 2,            # 2 columns
  layout_matrix = rbind(c(1, 2),  # Top two plots
                        c(3, 3)), # Bottom plot spans full width
  heights = c(1.75, 2)  # Give more space to bottom chart
)

#-----------------------------------------------------------------------------------------------------------------------------------------------------

shareholders_equity_mahindra <-mahindra_bs_long[mahindra_bs_long$Items %in% c("EqShCap", "Res_Surp","EqShApMony"), ]

print(shareholders_equity_mahindra)
##          Items     Category Year   Amount id
## 1      EqShCap SholderFunds 2024   599.62  1
## 2     Res_Surp SholderFunds 2024 51378.18  2
## 3   EqShApMony SholderFunds 2024   298.76  3
## 29     EqShCap SholderFunds 2023   599.05  1
## 30    Res_Surp SholderFunds 2023 42497.35  2
## 31  EqShApMony SholderFunds 2023   260.33  3
## 57     EqShCap SholderFunds 2022   598.30  1
## 58    Res_Surp SholderFunds 2022 38139.19  2
## 59  EqShApMony SholderFunds 2022   223.46  3
## 85     EqShCap SholderFunds 2021   597.39  1
## 86    Res_Surp SholderFunds 2021 33649.65  2
## 87  EqShApMony SholderFunds 2021   254.88  3
## 113    EqShCap SholderFunds 2020   596.52  1
## 114   Res_Surp SholderFunds 2020 33606.36  2
## 115 EqShApMony SholderFunds 2020   264.96  3
# Summing Shareholders' Equity by year
shareholders_equity_mahindra_sum <- shareholders_equity_mahindra %>%
  group_by(Year) %>%
  summarise(shareholders_equity_mahindra = sum(Amount))

# Print the result
print(shareholders_equity_mahindra_sum)
## # A tibble: 5 × 2
##   Year  shareholders_equity_mahindra
##   <chr>                        <dbl>
## 1 2020                        34468.
## 2 2021                        34502.
## 3 2022                        38961.
## 4 2023                        43357.
## 5 2024                        52277.
#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load necessary library
library(ggplot2)

# Creating the shareholders_equity_mahindra_sum data frame
shareholders_equity_mahindra_sum_data <- data.frame(
  Year = c(2020, 2021, 2022, 2023, 2024),
  shareholders_equity_mahindra_sum = c(34468, 34502, 38961, 43357, 52277) # Total Shareholders' Equity values
)

# Plotting Total Shareholders' Equity Trend
ggplot(shareholders_equity_mahindra_sum_data, aes(x = Year, y = shareholders_equity_mahindra_sum)) +
  geom_line(color = "skyblue", linewidth = 2) +  
  geom_point(color = "brown", size = 3.5) +
  labs(
    title = "Total Shareholders' Equity for Mahindra & Mahindra (2020–2024)",
    x = "Year",
    y = "Total Equity in 000's(cr.)"
  ) +
  scale_y_continuous(
    limits = c(32000, 54000),              # Setting y-axis limits
    breaks = seq(32000, 54000, by = 2000), # Setting the breaks on the y-axis
    labels = seq(32, 54, by = 2)           # Labeling the y-axis from 32 to 54
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load necessary library
library(ggplot2)

# Creating the shareholders_equity_mahindra_sum data frame
shareholders_equity_mahindra_sum_data <- data.frame(
  Year = c(2020, 2021, 2022, 2023, 2024),
  shareholders_equity_mahindra_sum = c(34468, 34502, 38961, 43357, 52277) # Total Shareholders' Equity values
)

# Plotting Total Shareholders' Equity Bar Chart 
ggplot(shareholders_equity_mahindra_sum_data, aes(x = factor(Year), y = shareholders_equity_mahindra_sum, fill = Year)) +
  geom_bar(stat = "identity", width = 0.6, show.legend = FALSE) +  
  scale_fill_gradient(low = "red", high = "green") +  
  geom_text(aes(label = shareholders_equity_mahindra_sum), 
            vjust = -0.5,          # Positioning labels above the bars
            color = "black", 
            size = 4, 
            fontface = "bold") + 
  scale_y_continuous(
    limits = c(0, 54000),                 # Setting y-axis limits
    breaks = seq(0, 54000, by = 6000),    # Setting breaks on y-axis
    labels = seq(0, 54, by = 6),          # Labeling the y-axis from 0 to 54
  ) +
  labs(
    title = "Total Shareholders' Equity Trend for Mahindra & Mahindra (2020–2024)",
    x = "Year",
    y = "Total Shareholders' Equity in 000's (in cr.))"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

print(net_profit_loss_mahindra)
##   Year   Amount
## 1 2024 10717.80
## 2 2023  6548.64
## 3 2022  4935.22
## 4 2021   268.66
## 5 2020  1330.55
print(shareholders_equity_mahindra_sum)
## # A tibble: 5 × 2
##   Year  shareholders_equity_mahindra
##   <chr>                        <dbl>
## 1 2020                        34468.
## 2 2021                        34502.
## 3 2022                        38961.
## 4 2023                        43357.
## 5 2024                        52277.
# Creating the return_on_equity_mahindra data frame
return_on_equity_mahindra <- data.frame(
  Year = net_profit_loss_mahindra$Year,           # Taking the Year column from net_profit_loss_mahindra
  ROE = net_profit_loss_mahindra$Amount / shareholders_equity_mahindra_sum$shareholders_equity_mahindra  # Calculating ROE
)

# Printing the return_on_equity_mahindra dataframe
print(return_on_equity_mahindra)
##   Year         ROE
## 1 2024 0.310950730
## 2 2023 0.189805089
## 3 2022 0.126670936
## 4 2021 0.006196501
## 5 2020 0.025452134
#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load necessary library
library(ggplot2)

# Creating the return_on_equity_mahindra_data frame
return_on_equity_mahindra_data <- data.frame(
  Year = c(2020, 2021, 2022, 2023, 2024),
  ROE = c(0.3110, 0.1898, 0.1267, 0.0062, 0.0255)  # ROE values
)

# Plotting line chart
ggplot(return_on_equity_mahindra_data, aes(x = Year, y = ROE)) +
  geom_line(color = "darkorange", linewidth = 2) +  
  geom_point(color = "blue", size = 3.5) +       
  labs(
    title = "Return on Equity (ROE) Trend for Mahindra & Mahindra (2020–2024)",
    x = "Year",
    y = "ROE"
  ) +
  scale_y_continuous(
    limits = c(-0.05, 0.35),                       # Adjusting y-axis limits 
    breaks = seq(-0.05, 0.35, by = 0.1),           # Setting breaks on y-axis
    labels = scales::label_percent(accuracy = 0.1) # Formatting labels as percentages
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

# Load necessary library
library(ggplot2)

# Creating the return_on_equity_data frame
return_on_equity_mahindra_data <- data.frame(
  Year = c(2020, 2021, 2022, 2023, 2024),
  ROE = c(0.3110, 0.1898, 0.1267, 0.0062, 0.0255)  # ROE values
)

# Plotting Return on Equity Bar Chart
ggplot(return_on_equity_mahindra_data, aes(x = factor(Year), y = ROE, fill = ROE > 0)) +
  geom_bar(stat = "identity", width = 0.6, show.legend = FALSE) +  
  scale_fill_manual(values = c("gold")) +  
  labs(
    title = "Return on Equity (ROE) Trend for Mahindra & Mahindra (2020–2024)",
    x = "Year",
    y = "ROE"
  ) +
  scale_y_continuous(
    limits = c(0, 0.35),                       # Adjusting y-axis limits 
    breaks = seq(0, 0.35, by = 0.05),           # Setting breaks on y-axis
    labels = scales::label_percent(accuracy = 0.1) # Formatting labels as percentages
  )+
  geom_text(aes(label = scales::percent(ROE, accuracy = 0.1)), 
            vjust = ifelse(return_on_equity_mahindra_data$ROE > 0, -0.5, 1.5), size = 5) +  
  theme_minimal() +
  geom_hline(yintercept = 0, linewidth = 0.5, color = "black") +  #Highlighting the x-axis line at y = 0
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 14),
    axis.title = element_text(size = 12),
    axis.text = element_text(size = 10)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------
# Load ggplot2 library
library(ggplot2)

# Create DF for ROE
ROE_data <- data.frame(
  Year = rep(c(2020, 2021, 2022, 2023, 2024), 2),
  Company = c(rep("Tata Motors", 5), rep("Mahindra & Mahindra", 5)),
  ROE = c(-0.2418, -0.1066, -0.0697, 0.1432, 0.4510,  
          0.0255, 0.0062, 0.1267, 0.1898, 0.3109)  
)

# Bar Chart
ggplot(ROE_data, aes(x = factor(Year), y = ROE, fill = Company)) +
  geom_bar(stat = "identity", position = "dodge", color = "black", linewidth = 1) +
  labs(title = "Return on Equity (ROE) Comparison: Tata Motors vs Mahindra & Mahindra", 
       subtitle = "(2020-2024)",
       x = "Year", 
       y = "Return on Equity (ROE)",
       caption = "Source: Financial Reports of Tata Motors & Mahindra & Mahindra") +
  scale_fill_manual(values = c("Tata Motors" = "steelblue",  
                               "Mahindra & Mahindra" = "darkorange")) +  
  geom_text(aes(label = round(ROE, 3)), 
            position = position_dodge(width = 0.9), 
            vjust = ifelse(ROE_data$ROE < 0, 1.5, -0.5),  
            size = 5, color = "black", fontface = "bold") +  
  scale_y_continuous(
    limits = c(-0.3, 0.5),  
    breaks = seq(-0.3, 0.5, by = 0.2)  
  ) + 
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 18, color = "black"),
    plot.subtitle = element_text(hjust = 0.5, size = 14, color = "gray40"),
    axis.title = element_text(size = 14, face = "bold"),
    axis.text = element_text(size = 12),
    legend.position = "top",
    legend.title = element_blank(),
    legend.text = element_text(size = 12, face = "bold"),
    panel.border = element_rect(color = "black", fill = NA, linewidth = 1.5)
  )

#-----------------------------------------------------------------------------------------------------------------------------------------------------

Conclusion:

Tata Motors had negative ROE from 2020 to 2022, indicating losses and poor returns for shareholders but showed a strong recovery in 2023 and 2024. Mahindra & Mahindra maintained a positive ROE throughout, with a steady increase, reflecting better profitability and shareholder value.

Final Verdict: Insights & Strategic Roadmap

In this project, we utilized various R tools and libraries such as ggplot2 for data visualization and dplyr for data manipulation. We used readxl to import financial data. Functions like group_by() helped in data transformation. We performed financial ratio analysis, including Net Profit Margin, Gross Profit Margin, etc. , using R’s mathematical operations. Data visualization techniques such as bar plots, line charts, and pie-charts provided insightful trends. The project enhanced our data visualization and analytical skills in R. Overall, it provided practical exposure to financial analytics using R Studio.