install.packages(“tidyverse”)
library(ggplot2)
library(dplyr) library(tidyr) library(readr) library(readxl)
CO2
View(CO2)
Xem trực tiếp
head(CO2)
library(dplyr) library(ggplot2) # để có dataset mpg
loaixe <- mpg %>% group_by(class) %>% summarise( soluong = n(), ttmin = min(hwy), ttmax = max(hwy), tbtt = mean(hwy), tvitt = median(hwy) ) View(loaixe)
#6. Biểu đồ hiệu suất tiêu hao nhiên liệu
hist(mpg$hwy)
ggplot(data = mpg)+ geom_histogram(mapping = aes(x= hwy))
#7 Biểu đồ so sánh
library(ggplot2)
ggplot(data = mpg) + geom_bar(mapping = aes(x = class))
ggplot(data = mpg) + geom_bar(mapping = aes(x = class), fill = “skyblue”) + theme_minimal() + labs(title = “Số lượng xe theo loại”, x = “Loại xe”, y = “Số lượng”)
#8. Lấy dữ liệu từ file excel library(readxl)
Superstar <- read_excel(“D:\TL Ngân\RBIDV\3.SUPERSTORE.xlsx”, sheet = 1)
View(Superstar)
creditdata <- read_excel(“D:\TL Ngân\RBIDV\creditdata.xlsx”, sheet = 1)
View(creditdata)
#9. Làm sạch dữ liệu với lỗi NA
credit_data <- creditdata credit_data[ is.na(credit_data)] <- 0
View(credit_data)
names(credit_data) <-gsub(” “,”_“, names(credit_data))
View(credit_data)
#Thống kê
theonhom <- credit_data%>% group_by(credit_data$Term)%>% summarise(soluong = n()) View(theonhom)
ggplot(data = credit_data)+ geom_bar(mapping = aes(x=Term)) labs( title = “Số lượng khách hàng theo nhóm”, x = “Nhóm”, y = “số lượng”)