内容来源: http://lmdvr.r-forge.r-project.org/figures/figures.html
本文根据其代码作些许修改和加注释,希望能帮助大家学习R语言!!
p的参数
data(Oats, package = "MEMSS")
## Figure 2.1
tp1.oats <- xyplot(yield ~ Block | Variety , data = Oats, type = 'a')
# type的参数看备注
print(tp1.oats)
#画图
dim(tp1.oats)
# Variety 的种类个数
dimnames(tp1.oats)
# Variety 的种类名字
备注:
“p” for points,
“l” for lines,
“b” for both,
“o” for both ‘overplotted’,
“h” for ‘histogram’ like (or ‘high-density’) vertical lines,
“s” for stair steps,
“S” for other steps, see ‘Details’ below,
aspect
## Figure 2.3
update(tp1.oats,aspect=1)
#比例 aspect=1,意味着 h:l=1
between
## Figure 2.5
update(tp1.oats, aspect =1 , layout = c(2, 3),
between = list(x =4, y = 0.5))
dotplot
## Figure 2.6
dotplot(variety ~ yield | site, barley,
layout = c(3, 2), aspect = 1,
groups = year, auto.key = list(space = 'right'),
main="Figure 2.6 点状图")
xyplot
#FIG 2.7
key.variety <- list(space = "right", text = list(levels(Oats$Variety)),
points = list(pch = c(2,4,5), col = c("blue","black","red")))
xyplot(yield ~ nitro | Block, Oats, aspect = 1, type = "b",
groups = Variety, lwd=1.2 ,key = key.variety,
lty = 1, pch = c(2,4,5),
col.line = "darkgrey", col.symbol = c("blue","black","red"),
layout=c(3,2),
xlab = "Nitrogen concentration (cwt/acre)",
ylab = "Yield (bushels/acre)",
main = "Yield of three varieties of oats",
sub = "A 3 x 2 split plot experiment with 6 blocks")
颜色对应的修改,比较简单
stack
## Figure 2.8
barchart(Class ~ Freq | Sex + Age, data = as.data.frame(Titanic),
groups = Survived, stack = TRUE, layout = c(4, 1),
auto.key = list(title = "Survived", columns = 2))
scale list(x=“free”)
#Figure 2.9
barchart(Class ~ Freq | Sex + Age, data = as.data.frame(Titanic),
groups = Survived, stack =TRUE, layout = c(2, 2),
auto.key = list(title = "Figure 2.9", columns = 2),
scales = list(x="free",y="free"))#图与图之间存在间隙