-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataAnalysis.R
More file actions
110 lines (104 loc) · 3.75 KB
/
Copy pathDataAnalysis.R
File metadata and controls
110 lines (104 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Load dataset
data <- read.csv("E:/BMWGlobalSales/bmw_global_sales_2018_2025.csv")
head(data) # Initial few rows
tail(data) # Last few rows
str(data) # structure of data
summary(data) # brief knowledge of the respective values
#Clean the dataset
# check missing values
colSums(is.na(data)) # no missing values
# Check duplicate
sum(duplicated(data)) # no duplicate values
#Basic Statistics
summary(data$Units_Sold)
summary(data$Avg_Price_EUR)
summary(data$Revenue_EUR)
# Units_sold
mean(data$Units_Sold) #mean
min(data$Units_Sold) #min
max(data$Units_Sold) #max
median(data$Units_Sold) #median
sd(data$Units_Sold) # standard deviation
aggregate(Units_Sold ~ Year, data, sum) # Year vs Unit_sold
aggregate(Units_Sold ~ Model, data, sum) # Unit_sold vs Model
# Avg_Price_EUR
mean(data$Avg_Price_EUR) #mean
min(data$Avg_Price_EUR) #min
max(data$Avg_Price_EUR) #max
median(data$Avg_Price_EUR) #median
sd(data$Avg_Price_EUR) # standard deviation
aggregate(Avg_Price_EUR ~ Year, data, mean) # Year vs Avg_Price_EUR
aggregate(Avg_Price_EUR ~ Model, data, mean) # Avg_Price_EUR vs Model
# Revenue_EUR
mean(data$Revenue_EUR) #mean
min(data$Revenue_EUR) #min
max(data$Revenue_EUR) #max
median(data$Revenue_EUR) #median
sd(data$Revenue_EUR) # standard deviation
aggregate(Revenue_EUR ~ Year, data, mean) # Year vs Revenue_EUR
aggregate(Revenue_EUR ~ Model, data, mean) # Revenue_EUR vs Model
# Correlation
cor(data$Units_Sold, data$Avg_Price_EUR) # correlation between Units_Sold and Avg_Price_EUR
cor(data$Units_Sold, data$Revenue_EUR) # correlation between Units_Sold and Revenue_EUR
# correlation between Revenue_EUR and Avg_Price_EUR will be almost one and doesn't give any meaningful insight
## Drawing various plots
library(ggplot2)
# Units Sold Trend Over Years
yearly_sales <- aggregate(Units_Sold ~ Year, data, sum)
ggplot(yearly_sales, aes(x=Year, y=Units_Sold, group=1)) +
geom_line(color="red", linewidth=1) +
geom_point(size=2) +
theme_minimal() +
ggtitle("Total Units Sold Over Years") +
xlab("Year") + ylab("Units Sold")
#Revenue Trend Over Years
yearly_revenue <- aggregate(Revenue_EUR ~ Year, data, sum)
ggplot(yearly_revenue, aes(x=Year, y=Revenue_EUR, group=1)) +
geom_line(color="blue", linewidth=1) +
geom_point(size=2) +
theme_minimal() +
ggtitle("Revenue Trend Over Years") +
xlab("Year") + ylab("Revenue (EUR)")
#Sales by Region (Bar Chart)
region_sales <- aggregate(Units_Sold ~ Region, data, sum)
ggplot(region_sales, aes(x=Region, y=Units_Sold, fill=Region)) +
geom_bar(stat="identity") +
theme_minimal() +
ggtitle("Sales by Region") +
xlab("Region") + ylab("Units Sold") +
theme(legend.position="none")
#Sales by Model (Bar Chart)
model_sales <- aggregate(Units_Sold ~ Model, data, sum)
ggplot(model_sales, aes(x=Model, y=Units_Sold, fill=Model)) +
geom_bar(stat="identity") +
theme_minimal() +
ggtitle("Sales by Model") +
xlab("Model") + ylab("Units Sold") +
theme(axis.text.x = element_text(angle=45, hjust=1),
legend.position="none")
#Units Sold vs Average Price (Scatter)
ggplot(data, aes(x=Avg_Price_EUR, y=Units_Sold)) +
geom_point(color="darkgreen") +
theme_minimal() +
ggtitle("Units Sold vs Average Price") +
xlab("Average Price (EUR)") +
ylab("Units Sold")
#Units Sold vs Revenue (Scatter)
ggplot(data, aes(x=Units_Sold, y=Revenue_EUR)) +
geom_point(color="purple") +
theme_minimal() +
ggtitle("Units Sold vs Revenue") +
xlab("Units Sold") +
ylab("Revenue (EUR)")
#Price Distribution (Histogram)
ggplot(data, aes(x=Avg_Price_EUR)) +
geom_histogram(fill="orange", bins=25) +
theme_minimal() +
ggtitle("Distribution of Average Price") +
xlab("Average Price (EUR)") +
ylab("Frequency")
# Price boxplot
ggplot(data, aes(y=Avg_Price_EUR)) +
geom_boxplot(fill="skyblue") +
theme_minimal() +
ggtitle("Boxplot of Average Price")