# Sample data for two populations
group1 <- rnorm(30, mean = 50, sd = 10)  # Population 1
group2 <- rnorm(25, mean = 55, sd = 15)  # Population 2

# Summarize data
summary(group1)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   33.94   45.90   51.48   51.17   57.08   65.41
summary(group2)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   19.65   40.20   50.91   51.69   68.67   87.94
# Perform Welch's t-test
t_test_result <- t.test(group1, group2, var.equal = FALSE)

# Display the result
t_test_result
## 
##  Welch Two Sample t-test
## 
## data:  group1 and group2
## t = -0.12572, df = 30.823, p-value = 0.9008
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -8.997843  7.953163
## sample estimates:
## mean of x mean of y 
##  51.16954  51.69188
library(ggplot2)

# Combine data into a data frame
data <- data.frame(
  value = c(group1, group2),
  group = c(rep("Group 1", length(group1)), rep("Group 2", length(group2)))
)

# Plot
ggplot(data, aes(x = value, fill = group)) +
  geom_density(alpha = 0.5) +
  labs(
    title = "Density Plot of Two Groups",
    x = "Value",
    y = "Density"
  ) +
  theme_minimal()