关于使用r代码绘制轮廓图 [英] about plot contour figure by using r code

查看:436
本文介绍了关于使用r代码绘制轮廓图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是R代码方面的老手。现在,在使用R代码绘制轮廓图形时遇到了一些麻烦。

I am a green-hand on R code. Now I meet some trouble in plotting contour figure by using R code.

我检查了help(filled.contour),它告诉您是否要绘制轮廓,x ,y应该都按升序排列。实际上,我是随机接收数据的,例如:

I have checked help(filled.contour) which tells that if you want to plot the contour, x,y should be both in ascending order. Actually, I receive the data randomly, like:

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

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

How can I plot the contour figure!? Here is my code:

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值。前两点与其余部分相距甚远,这使得整个数据集的结果看起来很粗略,因此我省略了它们。

The 'akima' package will do it. It is designed to handle irregularly spaced z values. The first two points were widely separated from the rest and that made the results from the whole dataset look rather sketchy, so I omitted them.

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

这篇关于关于使用r代码绘制轮廓图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆