2D Energy Surface plot example?

Issue #172 resolved
Former user created an issue

Hi,

Does anyone have an example on how to plot an Energy Surface, provided a plain-text file with 3 columns (i.e. PCA 1, PCA2 and Free Energy?)

Comments (3)

  1. Xinqiu Yao

    Hi,

    We don't have function to specifically deal with free energy data yet (although it is on the To-do list). But I think it is not very difficult if you check out a little bit the contourplot() function in the lattice package. Note that contourplot() takes a 2-D matrix as input, and so you have to convert your data first. For example,

    library(lattice)
    
    pc1=seq(-10,20)
    pc2=seq(-30,0)
    f = rnorm(length(pc1) * length(pc2))
    
    # here is your original 3-column data
    data <- cbind(rep(pc1, length(pc2)), rep(pc2, each=length(pc1)), f)
    
    # convert it into a 2-D matrix
    f.mat <- matrix(data[, 3], nrow=length(pc1))
    
    # plot
    contourplot(f.mat, row.values=pc1, column.values=pc2, region=TRUE, contour=FALSE, xlab="PC1", ylab="PC2")
    

    Type help(contourplot) to find more options to customize your plot.

  2. Barry Grant

    Certainly start with Xin-Qiu's example above but I do also encourage you to explore the many, many other options that are available for these types of plots.

    For example, check out Karline Soetaert's plot3D package vignette, "50 ways to plot a volcano" < http://cran.r-project.org/web/packages/plot3D/vignettes/volcano.pdf >.

    Also look at < http://rgm3.lab.nig.ac.jp/RGM/R_image_list > and search for 'plot3d'. These two were mentioned in a stakoverflow post that replicated a MatLab like surface plot: < http://stackoverflow.com/questions/20549540/how-to-create-3d-matlab-style-surface-plots-in-r >

    Here is another example from plot3D... (see attached)...

    # Composite image using functions within the plot3D package (note. will be slow to render)
    install.packages("plot3D")
    library(plot3D)
    
    persp3D(z = volcano, zlim = c(-60, 200), phi = 20,
          colkey = list(length = 0.2, width = 0.4, shift = 0.15,
            cex.axis = 0.8, cex.clab = 0.85), lighting = TRUE, lphi = 90,
          clab = c("","height","m"), bty = "f", plot = FALSE)
     # create gradient in x-direction
      Vx <- volcano[-1, ] - volcano[-nrow(volcano), ]
     # add as image with own color key, at bottom
      image3D(z = -60, colvar = Vx/10, add = TRUE,
          colkey = list(length = 0.2, width = 0.4, shift = -0.15,
            cex.axis = 0.8, cex.clab = 0.85),
         clab = c("","gradient","m/m"), plot = FALSE)
     # add contour
      contour3D(z = -60+0.01, colvar = Vx/10, add = TRUE,
          col = "black", plot = TRUE)
    

    surface.png

  3. Log in to comment