1.使用layout函數數生成一上一下繪圖布局,(Hint: 3圖寬度比 1:4:1;高度比 5:1:5)
## ch19_1
attach(crabs)
layout(matrix(c(0,1,0,0,0,0,0,2,0),3,3,byrow=TRUE)
,heights=c(5,1,5),
widths = c(1,4,1))
plot(y)之直方圖及密度圖
ch16_2 <- function()
{
x <- rnorm(100, 60, 12)
x.hist <- hist(x, freq
= F)
lines(density(x))
print(x.hist)
}
2.繪製一正七角星圖形
## ch19_2
deg2rad = function(deg) {
return((pi * deg) / 180)
}
ch19_2 <- function()
{
plot(c(-1,-1), c(1,1), type
= "n", xlab = "", ylab = "",
xaxs = "i",
yaxs = "i", xlim = c(-1.2, 1.2), ylim = c(-1.2, 1.2))
x1 = cos(deg2rad(77.1428));
y1 = sin(deg2rad(77.1428));
x2 = cos(deg2rad(25.7144));
y2 = sin(deg2rad(25.7144));
x3 = cos(deg2rad(51.4286));
y3 = sin(deg2rad(51.4286))
x <- c(cos(0), -x1, -x2,
x3, x3, -x2, -x1)
y <- c(sin(0), y1, -y2,
-y3, y3, y2, -y1)
polygon(x, y, col = 4,
density = NULL)
title("七角星")
}
dev.off()
dev.new()
ch19_2()
3.使用layout函數匯出FL對CL之散步圖及各自的直方圖(或箱型圖)
##ch19_3
library(MASS)
layout(matrix(c(0,2,3,1), 2, 2, byrow = TRUE),widths = c(1,3),
heights = c(1,3), respect = TRUE)
plot(crabs[,c(6,4)], main = "FL vs CL scatters")
hist(crabs$CL)
boxplot(crabs$FL, main = "boxplot of FL")