02.07.2013 Views

现代统计图形 - 科学网—博客

现代统计图形 - 科学网—博客

现代统计图形 - 科学网—博客

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.5 网格线 51<br />

1 > # 产生40个正态随机数<br />

2 > x = rnorm(40)<br />

3 > # 画线图<br />

4 > plot(x, xlab = "", type = "l")<br />

5 > # 请思考为什么坐标值要这样设置:多边形的连线路径<br />

6 > polygon(c(1, 1:40, 40), c(0, x, 0), col = "gray")<br />

7 > # 获取当前图形区域坐标范围,以便下用<br />

8 > xy = par("usr")<br />

9 > # 用白色矩形挡住了0以下的部分<br />

10 > rect(xy[1], xy[3], xy[2], 0, col = "white")<br />

11 > # 重画一遍x的线条<br />

12 > lines(x)<br />

13 > # 添加水平线<br />

14 > abline(h = 0, col = "lightgray")<br />

-2 -1 0 1 2<br />

x<br />

0 10 20 30 40<br />

图 4.7: 多边形和矩形结合使用的一个巧妙图示:将0上下的数值分别用不<br />

同颜色填充。本图也可以利用clip()函数更方便地完成,请读者自行查阅帮<br />

助。

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!