Galton’s data on the heights of parents and their children
## 'data.frame': 928 obs. of 2 variables:
## $ parent: num 70.5 68.5 65.5 64.5 64 67.5 67.5 67.5 66.5 66.5 ...
## $ child : num 61.7 61.7 61.7 61.7 61.7 62.2 62.2 62.2 62.2 62.2 ...
## 矩陣
zones <- matrix(c(2, 0, 1, 3), ncol=2, byrow=TRUE)
## 寬度4:1,高度1:4
layout(zones, widths=c(4/5, 1/5), heights = c(1/5, 4/5))
# 定義xh(暫不畫圖)
xh <- with(dta, hist(parent, plot=FALSE))
# 定義xh(暫不畫圖)
yh <- with(dta, hist(child, plot=FALSE))
# 最大數量
ub <- max(c(xh$counts, yh$counts))
# 繪製向日葵圖(花瓣越多,數據重疊越多)
par(mar=c(3, 3, 1, 1))
with(dta, sunflowerplot(parent, child))
# 繪製parent長條圖
par(mar=c(0, 3, 1, 1))
barplot(xh$counts, axes=FALSE, ylim=c(0, ub), space=0)
# 繪製child長條圖(horiz=T為水平長條圖)
par(mar=c(3, 0, 1, 1))
barplot(yh$counts, axes=FALSE, xlim=c(0, ub), space=0, horiz=TRUE)
# 在圖形旁邊添加文字(文字放在圖形下方、距離約2的位置,設置在圖形外)
par(oma=c(3, 3, 0, 0))
mtext("Average height of parents (in inch)", side=1, line=2,
outer=T, adj=0,
at=.4 * (mean(dta$parent) - min(dta$parent))/(diff(range(dta$parent))))
# 在圖形旁邊添加文字(文字放在圖形左方、距離約2的位置,設置在圖形外)
mtext("Height of child (in inch)", side=2, line=2,
outer=T, adj=0,
at=.4 * (mean(dta$child) - min(dta$child))/(diff(range(dta$child))))
