STA3050 Lec3笔记
par(**mfrow=c(3,2)**)
#实现一页多图的功能,一个图版三行两列。mfrow按行排序,mfcol按列排序。
hist(d$lnpd86,**freq=F**)
#freq=F 直方图采用density freq=T直方图采用frequency
lines(x,dnorm(x,mean(d$lnpd90),sd(d$lnpd90 )),**lty=2**)
Ity=2指采用第二种线条绘图
pie(d$lnpd90,labels=d$district, cex=0.8, main="log(density) HK1990")
#第一个参数是引用数据,决定了每个扇形比例,labels是每个扇形的名称,cex是缩放图表大小。
barplot(d$lnpd90, **horiz=T**, col=rainbow(20), xlim=c(0,25), legend.text=d$district, args.legend=list(x=25, y=23, cex=0.8), main="log(Density) HK1990")
#horiz=T 水平柱状图,xlim x轴的上下限,args.legend 图例右上角位置
prop.table(t(rs),margin=1)
#统计行/列所占百分比,margin=1指行,margin=2指列。
Normal probability plot (Normal‐QQ plot) #QQ图
#若散点图在直线y=x附近分布,则这两个样本是同等分布;若横坐标样本为标准正态分布且散点图是在直线y=x附近分布,则纵坐标样本符合正态分布,且直线斜率代表样本标准差,截距代表样本均值。
qqnorm() #增加图片
qqline() #增加参考线
boxplot(c(s86$NT,s90$NT)~rep(c(86,90),pch=21, each=length(s86$NT) ),main="NT")
plot(d$lnpd86,d$lnpd90,pch=21,main="Plot with case no.")
text(d$lnpd86-0.1,d$lnpd90+0.1,cex=0.6)
#pch是散点的图形样式,text是增加散点的序号,±0.1是避免与散点重合
matplot(t,type="l")
grid()
#matplot把这些图放到一个坐标轴里,gird增加网格线
#lag()只能在Time Series中使用
curve(x*sin(x),-4*pi,4*pi)
#一般数学函数图形绘制可以用curve()函数
points(x, y, ...) # adds points
lines(x, y, ...) # adds line segments
text(x, y, labels, ...) # adds text into the graph
abline(a, b, ...) # adds the line $y = a + bx$
abline(h = y, ...) # adds a horizontal line
abline(v = x, ...) # adds a vertical line
polygon(x, y, ...)# adds a closed and possibly filled polygonsegments(x0, y0, x1, y1, ...) # draws line segments arrows(x0, y0, x1, y1, ...) # draws arrows
symbols(x, y, ...)# draws circles, squares, thermometers, etc.
legend(x, y, legend, ...) # draws a legend
#图中增加元素