BARPLOT 
grade_count <- table(data$Grade) 
 
barplot(grade_count, 
        main = "Bar Plot of Grades", 
        xlab = "Grade", 
        ylab = "Frequency", 
        col = "lightblue") 




HISTOGRAM 
hist(data$Score, 
     main = "Histogram of Score", 
     xlab = "Score", 
     col = "lightgreen", 
     border = "black")




BOXPLOT 
boxplot(data$Score, 
main = "Boxplot of Score", 
ylab = "Score", 
col = "lightblue")




MULTI-BOXPLOT 
boxplot(data[, c("Score", "Height_cm", "Weight_kg")], 
main = "Boxplots of Variables", 
col = c("lightblue", "orange", "pink")) 



SCATTERPLOT 
plot(data$Height_cm, 
data$Weight_kg, 
main = "Scatter Plot: Height vs Weight", 
xlab = "Height (cm)", 
ylab = "Weight (kg)", 
pch = 19, 
col = "blue") 



HEATMAP 
# Select numeric columns 
num_data <- data[, c("Score", "Height_cm", "Weight_kg")] 
# Correlation Matrix 
cor_matrix <- cor(num_data) 
# Enhanced Heatmap 
heatmap(cor_matrix, 
main = "Correlation Heatmap", 
col = colorRampPalette(c("blue", "white", "red"))(100), 
scale = "none", 
margins = c(8, 8))




ggplot 
 
 specify dataset and mapping 
 geoms 
 
library(ggplot2) 
 
ggplot(data = data, 
       aes(x = Height_cm, 
           y = Weight_kg)) + 
  geom_point()



modify the point,colour and size 
ggplot(data = data, 
       aes(x = Height_cm, 
           y = Weight_kg)) + 
  geom_point(color = "blue", 
             size = 4)




add a line of best fit 
ggplot(data = data, 
       aes(x = Height_cm, 
           y = Weight_kg)) + 
  geom_point(color = "blue", 
             size = 4) + 
  geom_smooth(method = "lm", 
              se = FALSE, 
              color = "red")









Time-dependent graphs 
data <- read.csv("financial.csv") 
Time series slot 
ggplot(data, aes(x = Date)) + 
geom_line(aes(y = Sales, color = "Sales"), size = 1) + 
geom_line(aes(y = Profit, color = "Profit"), size = 1) + 
geom_line(aes(y = Expenses, color = "Expenses"), size = 1) + 
labs(title = "Time Series Analysis", 
y = "Value", color = "Metrics") + 
theme_minimal()




Area chart 
data_long <- data %>% 
pivot_longer(cols = c(Sales, Profit, Expenses), 
names_to = "Type", 
values_to = "Value") 
ggplot(data_long, aes(x = Date, y = Value, fill = Type)) + 
geom_area(alpha = 0.7, position = "stack") + 
labs(title = "Stacked Area Chart", 
y = "Value") + 
theme_minimal()







Slope graph  
slope_data <- data.frame(
Metric = c("Sales", "Profit", "Expenses"), 
Start = c(data$Sales[1], data$Profit[1], data$Expenses[1]), 
End   = c(data$Sales[36], data$Profit[36], data$Expenses[36]) 
) 
ggplot(slope_data, aes(x = 1, xend = 2, y = Start, yend = End)) + 
geom_segment(size = 1, color = "steelblue") + 
geom_point(size = 3) + 
geom_point(aes(x = 2, y = End), size = 3) + 
scale_x_continuous(breaks = c(1, 2), labels = c("Start", "End")) + 
labs(title = "Slope Graph: Start vs End Comparison") + 
theme_minimal()






Dumbell  
ggplot(slope_data, aes(y = Metric)) +
geom_segment(aes(x = Start, xend = End, y = Metric, yend = Metric), color = "grey") + 
geom_point(aes(x = Start), color = "blue") + 
geom_point(aes(x = End), color = "red") + 
theme_minimal()



Stream graph 
library(ggstream) 
library(ggplot2)
stream_data <- data.frame( 
  DATE = rep(data$DATE, 3), 
  Category = rep(c("Residential", 
                   "Commercial", 
                   "Industrial"), 
                 each = nrow(data)), 
  Production = c( 
    data$IPG2211A2N * 0.4, 
    data$IPG2211A2N * 0.35, 
    data$IPG2211A2N * 0.25 
  )
) 
 
ggplot(stream_data, 
       aes(x = DATE, 
           y = Production, 
           fill = Category)) + 
  geom_stream() + 
  labs(title = "Electric Production Stream Graph")  