dulieu_hh=read.csv("C:\\Users\\MINH ANH\\OneDrive\\Máy tính\\Thuc hanh PTDL.csv\\doanh_thu_ban_le.csv")
dim(dulieu_hh) # trả về c(nrow; ncol) # View(data_hh) để mở data 
## [1] 108   4
cat("So quan sat;", nrow(dulieu_hh), "\nSo bien:", ncol(dulieu_hh),"\n")
## So quan sat; 108 
## So bien: 4

Mô tả dữ liệu - sử dụng table1

library(table1)
## 
## Attaching package: 'table1'
## The following objects are masked from 'package:base':
## 
##     units, units<-
table1(~ doanh_thu | khu_vuc, data = dulieu_hh)
Bac
(N=36)
Nam
(N=36)
Trung
(N=36)
Overall
(N=108)
doanh_thu
Mean (SD) 330 (81.3) 330 (81.3) 330 (81.3) 330 (80.6)
Median [Min, Max] 330 [170, 490] 330 [170, 490] 330 [170, 490] 330 [170, 490]
table1(~ doanh_thu | san_pham, data = dulieu_hh)
A
(N=36)
B
(N=36)
C
(N=36)
Overall
(N=108)
doanh_thu
Mean (SD) 280 (70.0) 330 (70.0) 380 (70.0) 330 (80.6)
Median [Min, Max] 280 [170, 390] 330 [220, 440] 380 [270, 490] 330 [170, 490]

Trực quan hóa dữ liệu

Biểu đồ tổng doanh thu theo khu vực

library(ggplot2)
tong_kv <- aggregate(doanh_thu ~ khu_vuc, dulieu_hh, sum)

ggplot(tong_kv, aes(x = khu_vuc, y = doanh_thu)) +
  geom_col(fill = "steelblue") +
  labs(title = "Tong doanh thu theo khu vuc",
       x = "Khu vuc",
       y = "Tong doanh thu")

### Biểu đồ tổng doanh thu theo sản phẩm

library(ggplot2)
tong_sp <- aggregate(doanh_thu ~ san_pham, dulieu_hh, sum)

ggplot(tong_sp, aes(x = san_pham, y = doanh_thu)) +
  geom_col(fill = "orange") +
  labs(title = "Tong doanh thu theo san pham ",
       x = "San pham",
       y = "Tong doanh thu")

### Biểu đồ tổng doanh thu theo khu vực và sản phẩm

library(ggplot2)

tong_kv_sp <- aggregate(doanh_thu ~ khu_vuc + san_pham, dulieu_hh, sum)

ggplot(tong_kv_sp, aes(x = khu_vuc, y = doanh_thu, fill = san_pham)) +
  geom_col(position = "dodge") +
  labs(title = "Tong doanh thu theo khu vuc va san pham",
       x = "Khu vuc",
       y = "Tong doanh thu",
       fill = "San pham")

### Biểu đồ phân bố doanh thu sử dụng histogram

hist(dulieu_hh$doanh_thu,
     main = "Phân bố doanh thu",
     xlab = "Doanh thu",
     col = "lightblue",
     border = "black")