Introduction

Measures of Central Tendency

\[ \bar{x} = \frac{\sum x_i}{n} \]

Load Libraries

library(ggplot2)
library(plotly)
library(dplyr)

Generate Data

set.seed(42)
data <- data.frame(
  Category = rep(c("A", "B", "C"), each = 30),
  Value = c(rnorm(30, mean = 50, sd = 10),
            rnorm(30, mean = 60, sd = 15),
            rnorm(30, mean = 40, sd = 5))
)
head(data)

Histogram (ggplot2)

ggplot(data, aes(x = Value, fill = Category)) +
  geom_histogram(alpha = 0.6, bins = 10, position = "identity") +
  labs(title = "Histogram of Values by Category", x = "Value", y = "Frequency") +
  theme_minimal()

Boxplot (ggplot2)

ggplot(data, aes(x = Category, y = Value, fill = Category)) +
  geom_boxplot() +
  labs(title = "Boxplot of Values by Category", x = "Category", y = "Value") +
  theme_minimal()

3D Scatter Plot (Plotly)

Summary Statistics

summary_stats <- data %>%
  group_by(Category) %>%
  summarise(
    Mean = mean(Value),
    Median = median(Value),
    SD = sd(Value),
    Min = min(Value),
    Max = max(Value)
  )
print(summary_stats)
## # A tibble: 3 × 6
##   Category  Mean Median    SD   Min   Max
##   <chr>    <dbl>  <dbl> <dbl> <dbl> <dbl>
## 1 A         50.7   49.0 12.6   23.4  72.9
## 2 B         58.2   62.2 15.8   15.1  83.6
## 3 C         41.0   41.5  3.92  34.0  47.6

Mathematical Explanation

\[ s = \sqrt{ \frac{\sum (x_i - \bar{x})^2}{n-1} } \]

Conclusion

Thank You! 🚀