bumpchart를 그려봅시다. 미국에서 25세이상의 인구 중 고등학교를 졸업한 비율이 다음과 같다고 하면
# percentage of those over 25 years having completed high school in 10
# cities in the USA in 1990 and 2000
educattn <- matrix(c(90.4, 90.3, 75.7, 78.9, 66, 71.8, 70.5, 70.4, 68.4, 67.9,
67.2, 76.1, 68.1, 74.7, 68.5, 72.4, 64.3, 71.2, 73.1, 77.8), ncol = 2, byrow = TRUE)
rownames(educattn) <- c("Anchorage AK", "Boston MA", "Chicago IL", "Houston TX",
"Los Angeles CA", "Louisville KY", "New Orleans LA", "New York NY", "Philadelphia PA",
"Washington DC")
colnames(educattn) <- c(1990, 2000)
educattn
## 1990 2000
## Anchorage AK 90.4 90.3
## Boston MA 75.7 78.9
## Chicago IL 66.0 71.8
## Houston TX 70.5 70.4
## Los Angeles CA 68.4 67.9
## Louisville KY 67.2 76.1
## New Orleans LA 68.1 74.7
## New York NY 68.5 72.4
## Philadelphia PA 64.3 71.2
## Washington DC 73.1 77.8
먼저 1990년과 2000년의 자료를 높은 순서대로 순위를 매겨 bumpchart 를 그려봅니다. 이때 plotrix 패키지가 설치되어 있어야 합니다.
library(plotrix)
bumpchart(educattn, main = "Rank for high school completion by over 25s")
다음은 순위가 아닌 비율을 bumpchart로 그려봅니다.
# now show the raw percentages and add central ticks
bumpchart(educattn, rank = FALSE, main = "Percentage high school completion by over 25s")
# margins have been reset, so use
par(xpd = TRUE)
boxed.labels(1.5, seq(65, 90, by = 5), seq(65, 90, by = 5))
par(xpd = FALSE)
다음 함수는 sizetree입니다. 다음의 예를 보시죠.
sexhaireye <- data.frame(sex = factor(sample(c("Male", "Female"), 50, TRUE)),
hair = factor(sample(c("Blond", "Red", "Brown", "Black"), 50, TRUE)), eye = factor(sample(c("Gold",
"Green", "Blue"), 50, TRUE)))
tail(sexhaireye)
## sex hair eye
## 45 Male Red Green
## 46 Female Red Green
## 47 Female Black Green
## 48 Female Blond Blue
## 49 Female Brown Blue
## 50 Male Brown Green
shecol <- list(c("pink", "lightblue"), c("#000000", "#dddd00", "#886600", "#ee8800"),
c("blue", "gold", "green"))
sizetree(sexhaireye, main = "Sex, hair and eye color", col = shecol, toplab = c("Sex",
"Hair color", "Eye color"))
여자의 hair,eye 색깔을 크게 그려보면 다음과 같다.
# now expand the female part of the sizetree
sizetree(sexhaireye[sexhaireye[, 1] == "Female", ], main = "Sex, hair and eye color (Females only)",
col = shecol, toplab = c("Sex", "Hair color", "Eye color"))
다음은 treeDiag 입니다. 이 함수를 쓰려면 openintro 패키지를 설치해야 합니다.
library(openintro)
treeDiag(c("Breakfast?", "Go to class"), c(0.4, 0.11, 0.49), list(c(0.4, 0.36,
0.24), c(0.6, 0.3, 0.1), c(0.1, 0.4, 0.5)), c("one", "two", "three"), c("Statistics",
"English", "Sociology"))
(a),(b) 등을 붙여 설명을 하기 위해서는 solSub 인수를 이용합니다.
treeDiag(c("Dow Jones rise?", "NASDAQ rise?"), c(0.53, 0.47), list(c(0.75, 0.25),
c(0.72, 0.28)), solSub = list(c("(a)", "(b)"), c("(c)", "(d)")), solwd = 0.08)