data(iris)
aggregate(
Sepal.Length ~ Species,
data = iris,
FUN = function(x) c(
min = min(x),
max = max(x),
median = median(x)
)
)
## Species Sepal.Length.min Sepal.Length.max Sepal.Length.median
## 1 setosa 4.3 5.8 5.0
## 2 versicolor 4.9 7.0 5.9
## 3 virginica 4.9 7.9 6.5
library(ggplot2)
ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
stat_summary(fun = mean, geom = "col") +
labs(
title = "Giá trị trung bình Sepal.Length theo từng nhóm Species",
x = "Species",
y = "Mean Sepal.Length"
) +
theme_minimal()
