library(ggplot2)
# Dữ liệu iris có sẵn trong R
data(iris)
write.csv(iris, "iris.csv", row.names = FALSE)
# Tính toán
mean_petal <- mean(iris$Petal.Length)
max_petal <- max(iris$Petal.Length)
min_petal <- min(iris$Petal.Length)
# In kết quả (làm tròn 3 chữ số thập phân)
cat("Mean Petal.Length =", round(mean_petal, 3), "\n")
## Mean Petal.Length = 3.758
cat("Max Petal.Length =", max_petal, "\n")
## Max Petal.Length = 6.9
cat("Min Petal.Length =", min_petal, "\n")
## Min Petal.Length = 1
# Nếu chưa cài ggplot2 thì chạy: install.packages("ggplot2")
ggplot(iris, aes(x = Sepal.Width, y = Petal.Length, color = Species)) +
geom_point(size = 3) +
labs(
title = "Scatter: Sepal.Width vs Petal.Length (theo Species)",
x = "Sepal.Width (cm)",
y = "Petal.Length (cm)"
) +
theme_minimal()

import pandas as pd
import matplotlib.pyplot as plt
# Đọc dữ liệu
df = pd.read_csv("iris.csv")
# Xem 5 dòng đầu
df.head()
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 0 5.1 3.5 1.4 0.2 setosa
## 1 4.9 3.0 1.4 0.2 setosa
## 2 4.7 3.2 1.3 0.2 setosa
## 3 4.6 3.1 1.5 0.2 setosa
## 4 5.0 3.6 1.4 0.2 setosa
species_count = df["Species"].value_counts()
species_count
## Species
## setosa 50
## versicolor 50
## virginica 50
## Name: count, dtype: int64