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 xvg files and arrange their plots using ggpubr.
Note: Ensure dependency packages are installed:
install.packages(c("ggplot2", "stringr", "ggpubr"))
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 xvg file containing RMSD data generated by GROMACS rmsd_file_path <- system.file("extdata/rmsd.xvg", package = "xvm")
# Read the xvg file using read_xvg() function rmsd_data <- read_xvg(rmsd_file_path) # The imported xvg file is stored as a list, with the list name corresponding to the file name. names(rmsd_data)
The imported xvg file is stored as a list, so you can simply display the data using the str()
function.
str(rmsd_data[[1]])
The list contains two elements, each storing different pieces of information:
$data
: a data frame containing the xvg data.
$metadata
: other detailed information about the xvg file, including:
# Plot the xvg data using plot_xvg() function plot_xvg(rmsd_data)
The read_xvg()
function can accept multiple xvg file paths as a character vector.
# Similarly, you can also read multiple types of xvg files. multi_file_path <- dir(system.file("extdata", package = "xvm")) # Filter out xvg files using stringr package library(stringr) multi_file_path <- multi_file_path[str_detect(multi_file_path, ".xvg")] 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 xvg files at once in batch: multi_data <- read_xvg(multi_file_path) names(multi_data)
You can view the information of a single xvg file by indexing the list:
# Check the first xvg file info via indexing str(multi_data[[1]])
# Plot one of the xvg files using the plot_xvg() function: plot_xvg(multi_data[[1]])
Alternatively, use lapply()
to generate plots for each xvg file:
# Use lapply() to plot all the xvg files in batch mutli_xvg_plots <- lapply(multi_data, plot_xvg)
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_xvg_plots)
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.