3.3 標準的な高水準作図関数によるグラフ
サンプルコード
# 3.3.1節
Cyl.tbl <- table(Cylinders)
barplot(Cyl.tbl) # 図3.20
barplot(table(Cylinders)) # 図3.20と同じ
?barplot
barplot(Cyl.tbl, horiz=T) # 図3.21
barplot(Cyl.tbl,density=20,angle=60)
barplot(Cyl.tbl, density=c(1,2,5,10,50,100), angle=c(30,45,60,90,120,135)) # 図3.22
barplot(Cyl.tbl, col=c(1,2,3,4,5,6)) # 図3.23
cars.tbcyair<-table(Cylinders, AirBags)
barplot(cars.tbcyair,legend=rownames(cars.tbcyair)) # 図3.24
barplot(cars.tbcyair, beside=T,legend=rownames(cars.tbcyair)) # 図3.25
# 3.3.2節
tbcy <- table(Cylinders)
tbcy
pie(tbcy) # 図3.26
pie(tbcy, clockwise=TRUE) # 図3.27
pie(tbcy, radius=-1,clockwise=TRUE)
pie(tbcy, edges=8,clockwise=TRUE) # 図3.28
# 3.3.3節
ptcar <- prop.table(xtabs(~AirBags+Cylinders), 2)
barplot(ptcar,horiz=T,legend=rownames(ptcar)) # 図3.29
# 3.3.4節
# 図3.30
Cars93.nu <- subset(Cars93, Origin=="non-USA", select=c(Manufacturer,Model,
MPG.city,AirBags,DriveTrain,Horsepower,Length,Width))
row.names(Cars93.nu) <- with(Cars93.nu,paste(Manufacturer,Model))
dotchart(MPG.city,labels=row.names(Cars93.nu),cex=0.7)
Cars93.nus<-Cars93.nu[order(Cars93.nu$MPG.city),]
detach(Cars93)
attach(Cars93.nus)
dotchart(MPG.city,labels=row.names(Cars93.nu),cex=0.7,groups=DriveTrain)
# 図3.31
gcol <- rep("red",dim(Cars93.nus)[1])
gcol[DriveTrain=="4WD"] <- "green"
gcol[DriveTrain=="Rear"] <- "blue"
dotchart(MPG.city, labels=row.names(Cars93.nu), cex=0.7, groups=DriveTrain,col=gcol)
detach(Cars93.nus)
attach(Cars93)
図3.31
サンプルコード
# 3.3.5節
# 図3.32
plot(Nile,type="l")
ts.plot(Nile)
#
WorldPhones
matplot(WorldPhones,type="l") # 図3.33
図3.33
サンプルコード
ts.plot(WorldPhones,type="l",lty=1:7,col=1:7)
matplot(WorldPhones,type="b",pch=1:7)
matplot(rownames(WorldPhones), WorldPhones,type="b", pch=c(1:4,15,8,5), xlab="year",log="y") # 図3.34
図3.34
サンプルコード
# 3.3.6節
hist(Cars93$Length)
# 階級のbreakpointsをベクトルで与える
hist(Length, breaks=c(140,170,200,230,260))
# 級数を計算するアルゴリズムを指定する
hist(Length, breaks="Scott")
# 階級数を計算する関数を与える
hist(Length, breaks=function(x){sqrt(length(x))})
# 階級数を4とし,棒をグレーに塗る
hist(Length, breaks=4, col='gray')
hist(Length, plot=F)
(hist(Cars93$Length))
summaryhist <- hist(Cars93$Length)
summaryhist
# 3.3.7節
boxplot(Cars93$Length)
boxplot(Length,notch=TRUE, boxwex=1.2, staplewex=1.2)
boxplot(Cars93$Length,plot=FALSE)
boxplot(Length~Cylinders,data=Cars93)
boxplot(Length, Weight)
# 3.3.8節
plot(Length, Weight)
plot(Length, Weight,type="n")
text(Length, Weight)
rx=sample(1:5,100,replace=TRUE)
ry=sample(1:5,100,replace=TRUE)
plot(rx,ry)
sunflowerplotplot(rx,ry)
plot(jitter(rx),jitter(ry),xlab="rx",ylab="ry")
install.packages("HSAUR")
data(Forbes2000, package="HSAUR")
plot(marketvalue~sales,data=Forbes2000)
plot(marketvalue~sales,data=Forbes2000, log="xy")
plot(log(marketvalue)~log(sales),data=Forbes2000)
plot(marketvalue~sales,data=Forbes2000, log="xy", pch=".")
plot(marketvalue~sales,data=Forbes2000,log="xy",
pch=16,col=rgb(0,0,1,0.3))
install.packages("hexbin")
library(hexbin)
hbin<-with(Forbes2000,hexbin(log(sales),log(marketvalue)))
plot(hbin)
# 3.3.9節
coplot(Weight~Length | Cylinders)
coplot(Weight~Length | MPG.city)
coplot(Weight~Length | MPG.city, col=as.integer(AirBags))
# 3.3.10節
plot(iris[1:4])
pairs(iris[1:4])
?pairs
pairs(iris[1:4],diag.panel=panel.hist, upper.panel=panel.cor)
pairs(iris[1:4],pch=21,col = iris$Species)
# 3.3.11節
parcoord(iris[1:4])
parcoord(iris[1:4], col=as.integer(iris[,5]))
- 最終更新:2013-05-23 20:08:37