R语言画图

x=0
for(i in 1:60)x[i]=0
x[1]=20
for(i in 2:60)x[i]=x[i-1]+0.5
y=c(520,460,500,510,506,505,500,523,500,505,550,490,505,498,510,485,488,475,510,505,500,498,460,515,555,510,480,506,505,475,460,480,480,500,520,500,520,500,525,488,496,488,496,525,498,500,515,500,480,480,525,506,520,510,498,500,500,515,505,475)
plot(x,y,xlim=c(20,50),ylim=c(200,600),type="o",lwd=2,col=2,pch=19,cex=1.5,yaxs="i",xaxs="i",xlab="仿真时间",ylab="时延")
k=y/2
ed=c(365,320,350,353,348,349,348,364,348,350,395,350,352,345,360,348,340,346,360,350,348,350,320,360,365,353,348,348,355,325,340,345,340,345,355,352,350,353,350,348,352,340,349,358,343,355,348,350,340,338,358,350,360,353,345,348,348,355,348,320)
rd=c(348,310,352,360,359,358,355,364,350,348,400,348,350,348,350,340,338,347,350,350,356,340,315,362,400,356,340,345,353,325,325,325,
345,350,355,348,355,350,375,348,352,339,342,358,343,352,355,348,325,348,375,352,375,353,345,345,352,355,352,319)
lines(x,k,type="o",pch=23,lty=1,col="green")//添加线段
lines(x,ed,type="o",pch=21,lty=1,col="blue")
lines(x,rd,type="o",pch=24,lty=1,col="brown")
grid(nx=NA,ny=8,lwd=2)//添加分栏线

legend("topright",legend=c("往返时间","二分之一往返","实验结果","真实值"),col=c("red","green","blue","brown"),pch=c(19,23,21,24),lty=1)

//添加图例

R语言画图_第1张图片



注1:其中type设置画图的类型,有九种可能的取值,分别代表不同的样式:(1)'p')画点;(2)'l'画线5;(3)'b'同时


画点和线,但点线不相交;(4)'c'将type= 'b'中的点去掉,只剩下相应的线条部分;(5)'o'同时画点和线,且相互


重叠,这是它与type = 'b'的区别;(6)'h'画铅垂线;(7)'s'画阶梯线,从一点到下一点时,先画水平线,再画垂直


线;(8)'S'也是画阶梯线,但从一点到下一点是先画垂直线,再画水平线;(9)'n'作一幅空图,没有任何内容,但坐


标轴、标题等其它元素都照样显示。


注2:pch控制点的符号;pch = 19)实圆点、pch = 20)小实圆点、pch = 21)圆圈、pch = 22)正方形、pch = 23)菱


形、pch = 24)正三角尖、pch= 25)倒三角尖,其中,21-25可以填充颜色(用bg参数)


注3:lty控制连线的线型,可以是整数(1: 实线,2: 虚线,3: 点线,4: 点虚线,5: 长虚线,6: 双虚线),或者是不超过8


个字符的字符串(字符为从"0"到"9"之间的数字)交替地指定线和空白的长度,单位为磅(points)或象素,例如lty="44"


和lty=2效果相同。线条虚实样式:0 )不画线,1 )实线,2 )虚线,3 )点线,4 )点划线,5 )长划线,6 )点长划线


;或者相应设置如下字符串(分别对应前面的数字):'blank', 'solid', 'dashed', 'dotted', 'dot dash', 


'longdash', 'twodash';还可以用由十六进制的数字组成的字符串表示线上实线和空白的相应长度,如'F624'
添加图例
legend("topright",legend=c("AC正确率","MI归一化互信息"),col=c("blue","red"),pch=c(5,24),lty=1)
“bottomright” :图例的位置
legend: 内容
lty: 线的类型




你可能感兴趣的:(R语言画图)