R语言绘图基础资料.pptx

R 基础绘图 一、基础绘图工具 1. 绘图函数 2. 绘图参数介绍 3. 画图面板分割 4. 图形保存 二、图形案例 三、其它图形包;R绘制的图形;绘制地图;前言 学习 R 绘图没有什么技巧,只有记住常用参数的含义及用法,知道怎么去查找未知参数的含义及用法,再就是多多绘图,什么东西用得多了,自然就熟了。 如果需要更深入的了解,使用R 帮助。 R 使用帮助:?加上函数或参数名。例: ?plot,?legend demo(graphics) demo(persp) ;R 绘图界面简介 R 的绘图界面中总共分为三部分——outer margins, figure region, and plot region。 figure region 包括 plot region。;一、基础绘图工具 1. 绘图函数:在R中有两种绘图函数 1.1 高级绘图函数 创建一个新的图形;1. 绘图函数 1.2 低级绘图函数 在现有的图形上添加元素;2. 绘图参数介绍; plot(cars,font.lab=2,main=主标题,sub=副标题,type=p,xlim=c(7,20),ylim=c(20,100)) plot(cars,font.lab=2,main=主标题,sub=副标题,type=p,xlim=c(7,20),ylim=c(20,100),axes=F);plot(cars,font.lab=2,type=p) plot(cars,font.lab=2,type=l) plot(cars,font.lab=2,type=b) plot(cars,font.lab=2,type=o) plot(cars,font.lab=2,type=h) plot(cars,font.lab=2,type=s) plot(cars,font.lab=2,type=S) ;其它常用绘图参数;3. 画图面板分割;mar=c(a,b,c,d):设置 plot region 与 figure region 底部、 左边、上部、右边的距离,单位英寸。 mai=c(a,b,c,d):设置 plot region 与 figure region 底部、 左边、上部、右边的距离,单位是文本行数。 mgp=c(a,b,c):三个坐标轴成分的位置,轴文本标记、单位记号标记和轴位置与轴线距离;单位是文本行。 ;par(mgp=c(1.6,0.6,0),mar=c(3,3,2,1)) X=1:10;Y=1:10 cex_type=c(0.7,0.8,0.9,1,2,3,4,5,6,7) plot(X,Y,col=blue,pch=16, cex=cex_type, #绘图符号大小,1是正常大小 cex.axis=1.1, #坐标轴刻度数字大小 cex.lab=1.2, #坐标轴标签大小 cex.main=1.4, #标题文字大小 #cex.sub=1.3, #副标题文字大小 font.axis=3, #坐标轴刻度数字字体,斜体 font.lab=2, #坐标轴标签字体,粗体 font.main=4, #标题字体,粗斜体 #font.sub=1, #副标题字体,正常 main=字体, xlim=c(1,12),ylim=c(1,12)) text(X,Y,adj=0,labels=paste(cex=,cex_type),col=red,cex=1.2,font=3) ;R的绘图符号:pch=1:25;颜色名称:white, black, red, yellow,… colors() 数字代号:1, 2, 3, 4, 5, 6, 7, 8 颜色函数:rainbow, heat.colors, terrain.colors, topo.colors, cm.colors, colors();par(mgp=c(1.6,0.6,0),mar=c(3,3,2,1)) pch_type=c(1:5,15:19) X=1:10;Y=rep(6,10) plot(X,Y,col=1:10,pch=pch_type,cex=2,main=pch,font.lab=2) text(X,Y ,col=1:10,adj=-0.5,labels=paste(pch=,pch_type), srt=90) ;控制连线的类型 lty : 1: 实线,2: 虚线,3: 点线,4: 点虚线,5: 长虚线,6: 双虚线 控制线的宽度 lwd : 1为正常大小,1 为减小宽度,1为增加宽度;par(mgp=c(1.6,0.6,0),mar=c(3,3,2,1)) X=1:10;Y=1:10 line_type=c(1:6) lin

文档评论(0)

1亿VIP精品文档

相关文档