【问题标题】:R lattice wireframe: how to increase the resolution of 3D graphR格线框:如何提高3D图形的分辨率
【发布时间】:2013-12-18 11:32:39
【问题描述】:

我有一个问题经过一段时间的研究后没有答案。

temp.df<-subset(spread.df, x<5 & x>1 & y>1 & y<5)

wireframe((temp.df$z ~ temp.df$x + temp.df$y),
  scales=list(arrows=F), 
  screen = list(z = 40,x= -60) 
)

如果我运行这段代码,x 和 y 轴是从 2 到 4,其间只有一个增量,即 3。 这使得图形的分辨率非常低。有没有办法在不操纵我的原始数据集的情况下提高分辨率?更高分辨率是指细分线框的表面。

谢谢!

【问题讨论】:

  • temp.df 中有多少行?
  • @Troy 在对数据进行子集化后,我在 temp.df 中有 9 行。由于手头的数据点数量很少,该图表看起来非常粗糙。
  • 所以你基本上是在要求一个 2D 插值函数。这是一个:akima::interp
  • @CarlWitthoft 非常感谢!我想这就是我想要的。但它不会真正改变表面。您是否碰巧知道任何其他可以更好地表示我的数据的回归函数?
  • 您可能会尝试寻找二维样条函数,但我不知道有一个副手。

标签: r lattice wireframe


【解决方案1】:

好的,这里是使用akima 包对表面进行插值的方法。默认情况下,它会根据现有表面为您提供 40x40 的网格:

require(akima)
require(reshape2)

temp.df<-expand.grid(x=2:4,y=2:4,z=0)
temp.df$z<-rnorm(9,10,3)

surface<-melt(interp(temp.df$x,temp.df$y,temp.df$z)) # melt() stretches out the surface to x,y,z as you've put into the original example
flat<-surface[!is.na(surface$X1)&!is.na(surface$X2),] # drop the NAs

#CONVERT SCALES BACK (INTERP GIVES YOU A 40x40 grid over the existing range)

points<-data.frame(x=min(temp.df$x)+(flat$X1-1)/(40/diff(range(temp.df$x))),
                   y=min(temp.df$y)+(flat$X2-1)/(40/diff(range(temp.df$x))),
                   z=flat$value)

wireframe((points$z ~ points$x + points$y),
          scales=list(arrows=F), 
          screen = list(z = 40,x= -60) 
)

【讨论】:

  • 只要保证你不需要我上面的评论来得到这个答案:-)
  • 我想同时也有同样的想法!
  • 你们太棒了!非常感谢您的工作! points$z ~ points$x + points$y,这里有比这个更好的回归方法吗?我知道我也使用过这个,但我只是好奇是否还有另一个可以更好地代表数据。
猜你喜欢
  • 2020-03-06
  • 2010-10-19
  • 1970-01-01
  • 1970-01-01
  • 2017-02-13
  • 2013-01-06
  • 2020-06-04
  • 1970-01-01
  • 2016-03-04
相关资源
最近更新 更多