环境配置:
signif(x2, 3)
round(x2, 3)
setEPS()
postscript("myFigure.eps",width=2.756*4,height=1.870*4)
plot(rnorm(100), main="Hey Some Data")
dev.off()
pdf(file="myFigure.pdf",width=2.756*4,height=1.870*4)
plot_chap1_1b()
dev.off()
提取工作日
Sindex=seq.Date(from=as.Date("2010/01/01",format="%Y/%m/%d"),by="day",length.out=10)
Sindex[which(weekdays(Sindex) %in% c("星期一","星期二","星期三","星期四","星期五"))]
require(graphics)
a <- 2
bquote(a == a)
bquote(a == a)
quote(a == a)
bquote(a == .(a))
substitute(a == A, list(A = a))
plot(1:10, a*(1:10), main = bquote(a == .(a)))
## to set a function default arg
default <- 1
bquote( function(x, y = .(default)) x+y )
1、函数lines()其作用是在已有图上加线,命令为lines(x,y),其功能相当于plot(x,y,type="1") 两点连线
lines(c(0.1,0.1),c(0,0.1))
2、函数abline()可以在图上加直线,其使用方法有四种格式。
# 2.1 abline(a,b) 表示画一条y = a + bx的直线
a <- 4; b <- 2
abline(a,b)
# 2.2 abline(h=y) 表示画出一条过所有点得水平直线
y = 5
abline(h = y)
# 2.3 abline(v=x) 表示画出一条过所有点的竖直直线
abline(v = y)
# 2.4 abline(lm.obj) 表示绘出线性模型得到的线性方程
par(mar=c(1,1,1,1)+0.1,cex=0.8)
plot(0,0,type = 'l', axes=FALSE,xlab = '',ylab = '', xlim = c(-10,11), ylim = c(-10,11))
arrows(x0 = -11, y0 = 0, x1 = 11, y1 = 0, length = 0.1)
arrows(y0 = -11, x0 = 0, y1 = 11, x1 = 0, length = 0.1)
for(i in seq(-10,10,by=1)){
x = c(i,i);y = c(0,0.25)
lines(x,y)
if(i != 0) text(x[1],-0.5,i,cex = 0.6)
}
for(i in seq(-10,10,by=1)){
x = c(0,0.25); y = c(i,i)
lines(x,y)
if(i != 0) text(-0.5,y[1],i,cex = 0.6)
}
text(-0.25,-0.5,'0',cex = 0.6)
code = "aa>1"
x <- tryCatch(eval(parse(text = code)),error = function(e) e)
if(length(class(x)) > 1){
if(class(x)[2]=="error"){ cat(paste0(x)) }
}
x
score <- rnorm(n = 1000, m = 80, sd = 20)
hist(score, freq=FALSE, xlab="Score",main="Distribution of score",
col="lightgreen", xlim=c(0,150), ylim=c(0, 0.02))
curve(dnorm(x, mean=mean(score), sd=sd(score)),
add=TRUE, col="darkblue", lwd=2)