R画路

来源:互联网 发布:电脑帧数显示软件 编辑:程序博客网 时间:2024/05/18 00:15



主要连点连线

地名显示

用ggplot

p<-ggplot(locat1,aes(x=jingdu,y=weidu))+xlim(-5,60)+geom_segment(data = r5xy,color=col,size=1, aes(x = r5x1, y = r5y1, xend = r5x2, yend = r5y2))+geom_text(aes(label=city), size=5)
p


geom_segment(data = r5xy,color=col,size=1, aes(x = r5x1, y = r5y1, xend = r5x2, yend = r5y2))

两点连线,颜色

geom_text(aes(label=city), size=5)

显示城市名字











locat1<-read.csv("C:\\Users\\Administrator\\Desktop\\地理1.csv")

library(ggplot2)
locat2<-locat1[1:22,5:26]
locat2[is.na(locat2)]=0




x11<-c()
x1<-c()
x2<-c()
y1<-c()
y2<-c()
for (i in 1:22) {
  for (j in 1:22) {
if(locat2[i,j]==1&&i!=j)
{
x1<-c(x1,locat1[i,3])
x2<-c(x2,locat1[j,3])
y1<-c(y1,locat1[i,2])
y2<-c(y2,locat1[j,2])
}
  }
}
xy<-cbind(x1,x2,y1,y2)
xy<-as.data.frame(xy)
p<-ggplot(locat1,aes(x=jingdu,y=weidu))+geom_point(size=3,shape=21)+geom_text(aes(label=city), size=4)+geom_segment(data = xy, aes(x = x1, y = y1, xend = x2, yend = y2))
p




r1<-read.csv("C:\\Users\\Administrator\\Desktop\\刚果路径.csv")
r1x1<-c()
r1x2<-c()
r1y1<-c()
r1y2<-c()
r1xy<-cbind(r1x1,r1x2,r1y1,r1y2)
r1xy<-as.data.frame(r1xy)


for (i in 1:7) {
  for (j in 1:8) {
    
  if(r1[i+1,j]!=0)
  {
  r1x1<-c(r1x1,locat1[r1[i,j],3])
  r1x2<-c(r1x2,locat1[r1[i+1,j],3])
  r1y1<-c(r1y1,locat1[r1[i,j],2])
  r1y2<-c(r1y2,locat1[r1[i+1,j],2])
  }
  }
}
p<-ggplot(locat1,aes(x=jingdu,y=weidu))+geom_point(size=3,shape=21)+geom_text(aes(label=city), size=4)+xlim(-5,60)+geom_segment(data = r1xy, aes(x = r1x1, y = r1y1, xend = r1x2, yend = r1y2))
p


r2<-read.csv("C:\\Users\\Administrator\\Desktop\\苏丹路径.csv")
r2x1<-c()
r2x2<-c()
r2y1<-c()
r2y2<-c()
r2xy<-cbind(r2x1,r2x2,r2y1,r2y2)
r2xy<-as.data.frame(r2xy)
for (i in 1:6) {
  for (j in 6) {
    
    if(r2[i+1,j]!=0)
    {
      r2x1<-c(r2x1,locat1[r2[i,j],3])
      r2x2<-c(r2x2,locat1[r2[i+1,j],3])
      r2y1<-c(r2y1,locat1[r2[i,j],2])
      r2y2<-c(r2y2,locat1[r2[i+1,j],2])
    }
  }
}
p<-ggplot(locat1,aes(x=jingdu,y=weidu))+geom_point(size=3,shape=21)+geom_text(aes(label=city), size=4)+xlim(-5,60)+geom_segment(data = r2xy, aes(x = r2x1, y = r2y1, xend = r2x2, yend = r2y2))
p




r5<-read.csv("C:\\Users\\Administrator\\Desktop\\总路径.csv")
r5x1<-c()
r5x2<-c()
r5y1<-c()
r5y2<-c()
locat11<-data.frame(locat1[,3]+0.4,locat1[,2]+0.2,locat1[,3]-0.1,locat1[,2]-0.1,locat1[,3]+0.2,locat1[,2]+0.1)
c<-c(6,18,25:27,29:36,42)
for (j in c) {
  for (i in 1:8){
    
    if(r5[i+1,j]!=0)
    {
      if(j==6){
      r5x1<-c(r5x1,locat1[r5[i,j],3])
      r5x2<-c(r5x2,locat1[r5[i+1,j],3])
      r5y1<-c(r5y1,locat1[r5[i,j],2])
      r5y2<-c(r5y2,locat1[r5[i+1,j],2])
    }
    else if(j==18)
    {
      r5x1<-c(r5x1,locat11[r5[i,j],3])
      r5x2<-c(r5x2,locat11[r5[i+1,j],3])
      r5y1<-c(r5y1,locat11[r5[i,j],4])
      r5y2<-c(r5y2,locat11[r5[i+1,j],4])
    }
    else if(j==42)
    {
      r5x1<-c(r5x1,locat11[r5[i,j],5])
      r5x2<-c(r5x2,locat11[r5[i+1,j],5])
      r5y1<-c(r5y1,locat11[r5[i,j],6])
      r5y2<-c(r5y2,locat11[r5[i+1,j],6])
    }
    else 
    {
      r5x1<-c(r5x1,locat11[r5[i,j],1])
      r5x2<-c(r5x2,locat11[r5[i+1,j],1])
      r5y1<-c(r5y1,locat11[r5[i,j],2])
      r5y2<-c(r5y2,locat11[r5[i+1,j],2])
    }
    }
  }
}




col<-as.numeric(r5$col)
r5xy<-cbind(r5x1,r5x2,r5y1,r5y2,col)
r5xy<-as.data.frame(r5xy)


p<-ggplot(locat1,aes(x=jingdu,y=weidu))+xlim(-5,60)+geom_segment(data = r5xy,color=col,size=1, aes(x = r5x1, y = r5y1, xend = r5x2, yend = r5y2))+geom_text(aes(label=city), size=5)
p

0 0