Creating a trellised (faceted) thin-plate spline response surface

前端 未结 2 1553
不思量自难忘°
不思量自难忘° 2021-01-13 12:58

I am trying to plot a bunch of thin-plate spline response surfaces for measurements related to two continuous variables plus one discrete variable. So far, I have been subs

相关标签:
2条回答
  • 2021-01-13 13:05

    As noted in a comment, melt() can be used to reshape the Tps() output, then it can be reformatted a bit (to remove NA's), recombined into a single data frame, and plotted. Here are plots with ggplot2 and levelplot:

    library(reshape)
    library(lattice)
    
    LWsurfm<-melt(surf.te.outLW)
    LWsurfm<-rename(LWsurfm, c("value"="z", "Var1"="x", "Var2"="y"))
    LWsurfms<-na.omit(LWsurfm)
    SWsurfms[,"Morph"]<-c("SW")
    
    SWsurfm<-melt(surf.te.outSW)
    SWsurfm<-rename(SWsurfm, c("value"="z", "X1"="x", "X2"="y"))
    SWsurfms<-na.omit(SWsurfm)
    LWsurfms[,"Morph"]<-c("LW")
    
    LWSWsurf<-rbind(LWsurfms, SWsurfms)
    
    LWSWp<-ggplot(LWSWsurf, aes(x,y,z=z))+facet_wrap(~Morph)
    LWSWp<-LWSWp+geom_tile(aes(fill=z))+stat_contour()
    LWSWp
    

    ggplot2 image

    or: levelplot(z~x*y|Morph, data=LWSWsurf, contour=TRUE)

    lattice levelplot image

    0 讨论(0)
  • 2021-01-13 13:12
    require(rgl)
    open3d()
    plot3d
    surface3d(surf.te.outSW$x, surf.te.outSW$y, surf.te.outSW$z, col="red")
    surface3d(surf.te.outLW$x, surf.te.outLW$y, surf.te.outLW$z, col="blue")
    decorate3d()
          rgl.snapshot("OutRGL.png")
    

    enter image description here

    Another version where I scaled the x and y values by a factor of 10 and rotated to "look through" the gap. If this were your choice you might want to look at ?scaleMatrix

    enter image description here

    0 讨论(0)
提交回复
热议问题