繁体   English   中英

关于使用r代码绘制轮廓图

[英]about plot contour figure by using r code

我是R代码的绿色手。 现在我在使用R代码绘制轮廓图时遇到了一些麻烦。

我检查了帮助(filled.contour),它告诉你如果要绘制轮廓,x,y应该是按升序排列的。 实际上,我随机收到数据,如:

latitude, longitude, value
37.651098 140.725082 9519
37.650765 140.725248 9519
37.692738 140.749118 23600
37.692737 140.749118 9911
37.692695 140.749107 16591
37.692462 140.74902 6350
37.692442 140.749052 5507
37.692413 140.749148 5476
37.692383 140.74929 7069
37.692357 140.749398 6152
37.692377 140.749445 6170
37.692355 140.749587 7163
37.692298 140.749672 6831
37.692292 140.749787 6194
37.692283 140.749903 6696
37.692342 140.750007 8204
37.692585 140.750037 2872
37.692648 140.749948 3907
37.692655 140.749827 4891
37.692667 140.749687 4899

如何绘制轮廓图?? 这是我的代码:

args <- commandArgs(trailingOnly = TRUE) 
data1 <- args[1]
outputDir <- args[2]
outputFig = paste(outputDir, "Cs13x.jpeg",sep="");
jpeg(file = outputFig, width = 800,height=600, pointsize=20)
pinkcol <- rgb(1,0.7,0.7)

gpsdata <- read.table(file=data1,sep=" ");
lat <- as.vector(gpsdata[,1]);
lon <- as.vector(gpsdata[,2]);
datas <- as.vector(gpsdata[,3]);
datas <- abs(datas)
#---Convert gpsdata into x,y coordinate---#
# Convert degree into value
lat_pi <- lat*pi/180;
lon_pi <- lon*pi/180;
# calculate the value into corresponding x,y coordinate
x = cos(lat_pi) * cos(lon_pi);
y = cos(lat_pi) * sin(lon_pi);
#----------#
dataMatrix = matrix(datas, nrow = length(datas), ncol=length(datas));
plot.new()
filled.contour(sort(x),sort(y, decreasing = TRUE),dataMatrix, col = rainbow(100),     main="Contour Figure of Cs13x"); (**WRONG HERE!!!**)
dev.off()

<-------------- FINISH LINE ----------->

'akima'套餐会做到这一点。 它旨在处理不规则间隔的z值。 前两个点与其余点分开很广,这使得整个数据集的结果看起来相当粗略,所以我省略了它们。

 require(akima)
 gps.interp <- with( gpsdata[-(1:2), ], interp(x=latitude, y=longitude, z=value))
 contour(gps.interp)

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM