繁体   English   中英

使用R中的简单数据集绘制轮廓图

[英]Contour plot using the simple set of data in R

嗨,我一直在尝试使用简单的数据集创建简单的轮廓。

使用的数据集如下:

 dput(elevation)
structure(list(x = c(1L, 2L, 3L, 5L, 10L, 12L, 13L, 9L), y = c(5L, 
20L, 18L, 25L, 31L, 25L, 8L, 12L), z = c(5L, 10L, 15L, 8L, 7L, 
6L, 2L, 4L)), .Names = c("x", "y", "z"), class = "data.frame", row.names = c("1", 
"2", "3", "4", "5", "6", "7", "8"))

我只是将以上数据合并到一个名为levation.csv的文件中

我使用了黄土和expand.grid函数进行插值。 在黄土模型中我们如何选择程度和跨度?

我用来绘制的代码如下:

require(ggplot2)    
require(geoR)
elevation <- read.table("elevation.csv",header=TRUE, sep=",")
elevation

elevation.df <- data.frame(x=elevation$x,y=elevation$y,z=5*elevation$z)
elevation.df
elevation.loess=loess(z~x*y, data=elevation.df,degree=2,span=0.25)
elevation.fit=expand.grid(list(x=seq(1,13,2),y=seq(5,30,4)))
elevation.fit[1:20,]
z = predict(elevation.loess,newdata=elevation.fit)
elevation.fit$Height=as.numeric(z)
v <- ggplot(elevation.fit,aes(x,y,z=Height))
v1 <- v+stat_contour(aes(colour=..level..))+geom_point(data=elevation.df,aes(x=x,y=y,z=z))
direct.label(v1)

我不确定我得到的结果是否是准确的结果。 任何人都可以使用其他任何方法验证此结果并共享视图吗? 实际上,我必须处理一个大型数据集,并希望首先从简单的事情开始。

我在上面的代码中得到的输出如下:

在此处输入图片说明

这是处理大量数据集的好方法吗?

谢谢。

我得到这个...警告和关于没有名为direct.label函数的错误direct.label

Warning messages:
1: In simpleLoess(y, x, w, span, degree, parametric, drop.square, normalize,  :
  span too small.   fewer data values than degrees of freedom.
2: In simpleLoess(y, x, w, span, degree, parametric, drop.square, normalize,  :
  pseudoinverse used at 0.23095 0.70587
3: In simpleLoess(y, x, w, span, degree, parametric, drop.square, normalize,  :
  neighborhood radius 1.9692
4: In simpleLoess(y, x, w, span, degree, parametric, drop.square, normalize,  :
  reciprocal condition number  0
5: In simpleLoess(y, x, w, span, degree, parametric, drop.square, normalize,  :
  There are other near singularities as well. 2.063

在此处输入图片说明

在这种数据贫乏的情况下,什么是“正确的”只是判断的问题。 在2D范围的覆盖范围如此分散的情况下,我将考虑标记点的z值。 这些警告标志着数学越来越“紧张”。 我认为这表明y = 30以上的区域存在问题。

在此处输入图片说明

暂无
暂无

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

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