关系网络图代码
plottest111=function(r,rpoints,mat){
a.col=ncol(mat)
if(a.col%%2==0)
{
n=2*(1:a.col)-1
xplace=r*cos(pi/2+2*pi/a.col/2*n)
yplace=r*sin(pi/2+2*pi/a.col/2*n)
}else
{
xplace=r*cos(pi/2+(2*pi/a.col*((1:a.col)-1)))
yplace=r*sin(pi/2+(2*pi/a.col*((1:a.col)-1)))
}
plot(0,0,col="white",xlim=c(-1.25*r,1.25*r),ylim=c(-1.25*r,1.25*r),frame.plot=F,axes=F,xlab="",ylab="")
for(i in 1:a.col)
{
for(j in 1:i)
if(mat!=0)
{
a=xplace;b=yplace
lines(x=a,y=b,col="gray",lwd=1.25*mat)
}
}
par(new=T)
plot(x=xplace,y=yplace,col=rainbow(100),pch=16,cex=rpoints,xlim=c(-1.25*r,1.25*r),ylim=c(-1.25*r,1.25*r),frame.plot=F,axes=F,xlab="",ylab="")
points(xplace,yplace,cex=rpoints,pch=1,col="red")
text(x=xplace,y=yplace,names(mat))
}
###参数部分:r 画面的半径
r=3;rpoints=4
par(mfrow=c(2,4))
###点的坐标以及画图
for(i in 3:10)
{
b=matrix(sample(0:5,replace=T,size=i^2,prob=c(0.6,0.1,0.08,0.08,0.08,0.06)),ncol=i)
b=as.data.frame(b)
names(b)=letters
rownames(b)=letters
b=b
b[!(upper.tri(b)|lower.tri(b))]=0
plottest111(b,r=r,rpoints=rpoints)
}
页:
[1]