knitr::opts_chunk$set( collapse = TRUE, comment = "#>", error = FALSE )
This document demonstrates how to use the xvm package and its functions with sample datasets and plots. It also shows how to read multiple xpm files and arrange their plots using ggpubr.
Note: Ensure dependency packages are installed:
install.packages(c("ggplot2", "stringr", "ggpubr", "ggnewscale"))
Load the xvm package:
# Load the xvm package library(xvm)
Load other dependency packages:
# Load dependency packages library(ggplot2)
Retrieve the path to the example file included in the package:
# This example file is an xpm file containing (free energy landscape, FEL) data generated by GROMACS gibbs_file_path <- system.file("extdata/gibbs.xpm", package = "xvm")
# Read the xpm file using read_xpm() function gibbs_data <- read_xpm(gibbs_file_path) # The imported xpm file is stored as a list, with the list name corresponding to the file name. names(gibbs_data)
The imported xpm file is stored as a list, so you can simply display the data using the str()
function.
str(gibbs_data[[1]],max.level = 1)
The list contains seven elements, each storing different pieces of information:
$data
: a data frame containing the xpm data.
$title
: the main title.
$legend
: the legend labels.
$x_label
: the label for the x-axis.
$y_label
: the label for the y-axis.
$color_map
: other detailed information about the xpm file, including:
$color_values
: other detailed information about the xpm file, including:
# Plot the xpm data using plot_xpm() function plot_xpm(gibbs_data)
The read_xpm()
function can accept multiple xpm file paths as a character vector.
# Similarly, you can also read multiple types of xpm files. multi_file_path <- dir(system.file("extdata", package = "xvm")) # Filter out xpm files using stringr package library(stringr) multi_file_path <- multi_file_path[str_detect(multi_file_path, ".xpm")] print(multi_file_path) # Set the full xvg file paths multi_file_path <- file.path(system.file("extdata", package = "xvm"), multi_file_path )
# Read multiple xpm files at once in batch: multi_data <- read_xpm(multi_file_path) names(multi_data)
You can view the information of a single xpm file by indexing the list:
# Check the first xpm file info via indexing str(multi_data[[1]],max.level = 1)
Alternatively, use lapply()
to generate plots for each xpm file:
# Use lapply() to plot all the xpm files in batch mutli_xpm_plots <- lapply(multi_data, plot_xpm)
Finally, arrange all plots into a single layout using the ggarrange()
function from the ggpubr package:
# Arrange the plots using ggpubr library(ggpubr) ggarrange(plotlist = mutli_xpm_plots)
For xpm files representing free energy landscapes, xvm also provides a pseudo-3D plotting function plot_xpm_facet()
.
The upper plot has PC1 on the x axis, G (kJ/mol) on the y axis, and the color indicates the distance in PC2.
The lower plot has PC2 on the x axis, G (kJ/mol) on the y axis, and the color represents the distance in PC1.
# Usage is similar to the plot_xpm() function plot_xpm_facet(gibbs_data)
xvm also provides a 3D plotting function plot_xpm_3d()
using plotly
package.
# Usage is similar to the plot_xpm() function plot_xpm_3d(gibbs_data)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.