Biểu đồ tròn: pie() Biểu đồ phân bố: hist() Biểu đồ hộp: boxplot() Biểu đồ thanh: barplot() Biểu đồ tương quan: plot(), scatterplot() http:www.rbloggers.com Packages: ggplot2RcmdrPlugin.KMggplot2
Trang 11
Trang 3 pcfm (percent fat mass)
bmc (bone mineral contents)
3
Trang 11Tần số theo nhóm : barplot
agegroup <- cut(age, 3)
agesex <- table(sex, agegroup)
barplot(agesex, xlab="Age group")
barplot(agesex, beside=T, xlab="Age group")
Trang 1212
Trang 16Phân phối số liệu: Histogram
Trang 17Phân phối số liệu: Histogram
Trang 18Phân phối số liệu: Hàm mật độ-plot(density)
hist(age, main="Distribution of lean mass")
plot(density(age), main="Distribution of age")
Trang 19Phân phối chuẩn? qqnorm
Trang 20Tính liên tục của số liệu: stripchart
stripchart(age)
Trang 22Tính liên tục của số liệu: stripchart
Trang 23Tóm tắt của số liệu liên tục:boxplot
LMMin 1st Qu Median Mean 3rd Qu Max
18.51 31.91 35.92 35.65 40.14 46.63
FMMin 1st Qu Median Mean 3rd Qu Max
2.990 4.250 5.270 6.500 8.795 12.800
Trang 24Tóm tắt của số liệu liên tục: boxplot
24
boxplot(fm ~ sex) boxplot(lm ~ sex)
Trang 25Phân tích mức độ liên kết: scatter plot
Trang 26Phân tích mức độ liên kết: scatter plot
Trang 27Phân tích mức độ liên kết: scatter plot
27
plot(lm ~ age, pch=ifelse(sex=="M", "M", "F"),
xlab="Age", ylab="Kg")
M M
M
M
M
M M
M
M M
F F
M M
Trang 28Phân tích nhiều liên kết-multiple associations
data <- data.frame(age, weight, lm, fm, bmc)
Trang 30Phân tích nhiều sự liên kết –nhiều đồ thị
matrix.cor <- function(x, y, digits=2, prefix="",
cex.cor){ usr <- par("usr"); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r <- abs(cor(x, y))
txt <- format(c(r, 0.123456789), digits=digits)[1] txt <- paste(prefix, txt, sep="")
if(missing(cex.cor)) cex <- 0.8/strwidth(txt) test <- cor.test(x,y) # borrowed from printCoefmat Signif <- symnum(test$p.value, corr = FALSE, na = FALSE, cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), symbols = c("***",
Trang 32Tóm lược
Biểu đồ tròn: pie()
Biểu đồ phân bố: hist()
Biểu đồ hộp: boxplot()
Biểu đồ thanh: barplot()
Biểu đồ tương quan: plot(),
scatterplot()
http://www.r-bloggers.com/
Packages: ggplot2/RcmdrPlugin.KMggplot2
32
Trang 33Bài tập 1
đồ thị Pie:
Xuất hiện tỉ lệ % cùng Pie
Cài đặt thêm packages:
ggplot2/RcmdrPlugin.KMggplot2 )
33
Trang 34obesity <- read.table("obesity_data.txt", header=TRUE)
# Vẽ đồ thị phân bố pcfat và xem xét ảnh hưởng của gender
Trang 35Ví dụ- đồ thị
35
Trang 36Mục tiêu
36
Trang 37Code-Hàm hist
hist ( pcfat ,breaks=20, col=“blue”, border=“white”, xlab=“Percent
body fat”, ylab=“Probability”,
prob=T, main=“ Distribution of
PBF”);
lines (density(na.omit( pcfat )),
col=“red”, lwd=3)
37
Trang 38Percent body fat Probability
Trang 40Code-Hàm boxplot
xlim, ylim, col, border,
horizontal)
col=“blue”, xlab=“Percent body
fat”, main=“Percent body fat”,
horizontal=T)
40
Trang 41Percent body fat
Percent body fat
Trang 42Code-Hàm plot
xlab, ylab,xlim, ylim,
col, lwd)
lwd)
42
Trang 45Plot(pcfat~bmi, pch=16, col=“blue”, xlab=“BMI”,
ylab=“Percent body fat”)
Trang 48scatterplot(pcfat~bmi| gender, reg.line=F,
Trang 54Tuổi Tần số