R点阵线框:如何提高3D图形的分辨率

时间:2013-12-02 17:00:23

标签: r lattice wireframe

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

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。 这使图表的res非常低。有没有办法在不操纵原始数据集的情况下提高分辨率?通过更高的分辨率,我的意思是细分线框的表面。

谢谢!

1 个答案:

答案 0 :(得分:3)

好的,您可以使用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) 
)

enter image description here