load("./crimtab.RData")
산점도를 여러 유형으로 표현하기 위하여 필요한 패키지 설치
# install.packages("hexbin", repos = "http://cran.rstudio.com")
library(hexbin)
crimtab.bin 계산
crimtab.bin <- hexbin(crimtab.long.df$height, crimtab.long.df$finger, xbins = 50)
Plots
par(mfrow = c(2, 2))
plot(crimtab.long.df)
plot(crimtab.long.df, pch = 20)
# smoothScatter(crimtab.long.df[,"height"], crimtab.long.df[,"finger"], xlab = "height", ylab = "finger")
# smoothScatter(crimtab.long.df[,"height"], crimtab.long.df[,"finger"], nbin = 32, xlab = "height", ylab = "finger")
smoothScatter(crimtab.long.df, xlab = "height", ylab = "finger")
smoothScatter(crimtab.long.df, nbin = 32, xlab = "height", ylab = "finger")
Plot crimtab.bin
par(mfrow = c(1, 1))
plot(crimtab.bin, xlab = "height(inches)", ylab = "finger length(cm)")
산점도와 함께 주변분포 표시
par(mar = c(4, 4, 1, 1))
par(fig = c(0, 0.8, 0, 0.8))
plot(crimtab.long.df, pch = 20)
par(fig = c(0, 0.8, 0.68, 1), new = TRUE)
# hist(crimtab.long.df[, "height"], axes = FALSE, ann = FALSE)
hist(crimtab.long.df$height, axes = FALSE, ann = FALSE)
par(fig = c(0.68, 1, 0, 0.8), new = TRUE)
# barplot(table(cut(crimtab.long.df[, "finger"], breaks = 10)), space = 0, col = "white", horiz = TRUE, axes = FALSE, axisnames = FALSE)
barplot(table(cut(crimtab.long.df$finger, breaks = 10)), space = 0, col = "white", horiz = TRUE, axes = FALSE, axisnames = FALSE)
par(fig = c(0, 1, 0, 1))
par(mar = c(5, 4, 1, 1) + 0.1)
persp()
를 활용하면 다양한 각도에서 3차원 겨냥도를 그려볼 수 있음. \(x\) 축은 행, \(y\) 축은 열에 펼쳐진 격자를 0에서 1까지로 조정. theta
와 phi
는 박스를 돌려보는 각도이고, expand
는 박스 높이의 상대적인 비율임. \(x\) 축과 \(y\) 축의 라벨 이외에는 디폴트값을 적용시킨 겨냥도와 적절히 조정한 겨냥도를 비교해 볼 것,par(mfrow = c(2, 2))
persp(crimtab.2, xlab = "Finger Length", ylab = "Height")
persp(crimtab.2, xlab = "Finger Length", ylab = "Height", theta = 90, phi = 30, expand = 0.5, scale = TRUE)
persp(crimtab.2, xlab = "Finger Length", ylab = "Height", theta = 135, phi = 30, expand = 0.5, scale = TRUE)
persp(crimtab.2, xlab = "Finger Length", ylab = "Height", theta = 45, phi = 45, expand = 0.5, scale = TRUE)
par(mfrow = c(1, 1))