A Package for Plotting Insect Electrical Penetration Graph Signals in R!
- Project Description
- Installing EPGplotR
- Using EPGplotR
- Example Figure Generated by EPGplotR
- Key Features
- Getting Started
- Contributing
- License
EPGplotR is a powerful R package designed to simplify the visualization of insect electrical penetration graph (EPG) data. It enables users to:
- Load EPG Files: Automatically load
.DXX
file formats (Stylet+ DAQ output files). - Load ANA Files: Import corresponding
.ANA
files for plot annotations. - Visualize Signals: Generate high-quality plots of EPG signals (both interactive and static).
- Annotate and Analyze: Label recordings with behavioral annotations and segment key areas of interest.
- Customize Plots: Built on the robust frameworks of
ggplot2
andplotly
, allowing extensive user customizations.
With just four commands, users can produce publication-ready figures. EPGplotR makes it easy to generate beautiful visualizations while offering significant flexibility for advanced users.
Before installing EPGplotR
, ensure you have the following tools installed:
Once these are installed, you can install EPGplotR using the install_github()
function from the devtools
package.
-
Install
devtools
Package (if not already installed):install.packages("devtools")
-
Load
devtools
into Your Environment:library(devtools)
-
Install EPGplotR from GitHub:
install_github("dankunk/EPGplotR")
-
Load EPGplotR:
library(EPGplotR)
Once you've loaded EPGplotR
into your environment using library(EPGplotR)
, you're ready to start using EPGplotR.
No need to supply a path to all the recording files manually. Simply run load_d0x_files()
, select the first hour file for the recording of interest (i.e. .D01), and EPGplotR will handle the rest!
# Load EPGplotR
library(EPGplotR)
# Load a recording by selecting the file via the file explorer
rec_dt <- load_d0x_files()
# Alternatively, provide a direct path using the filepath argument:
rec_dt <- load_d0x_files(filepath = "C:/Users/user/My_EPG_file_folder/recording1_ch1.D01")
After loading the recordings, load the corresponding .ANA
file for annotations.
# Load the corresponding ANA file via the file explorer:
ana_dt <- load_ana_file()
# Alternatively, specify the file path directly:
ana_dt <- load_ana_file(filepath = "C:/Users/user/My_ANA_file_folder/recording1_ch1.ANA")
# Or if you don't have an ANA file, proceed to the plotting functions and use no_ana = TRUE
Use the assign_behavior_codes()
function to add behavioral annotations from the .ANA
file to your recording data.
# Annotate the rec_dt datatable with behavioral annotations:
assign_behavior_codes(rec_dt, ana_dt)
Voila! Now you're ready to plot your data. EPGplotR offers two main plotting options:
-
Interactive Plots: Utilize
plotly
with theplot_signal()
function. -
Static Plots: Utilize
ggplot2
with thegg_plot_signal()
function.
This method will use plotly
via the plot_signal()
function.
To expedite plotting, EPGplotR offers a downsampling capability that defaults to downsampling the signal by a factor of 10Hz. To preserve proper waveform characteristics, set downsample_rate = 1
.
# Interactive plots with plotly using plot_signal()
plot_signal(rec_dt)
# Ensure waveform characteristics and behavioral transitions remain intact by setting downsample_rate = 1
plot_signal(rec_dt, downsample_rate = 1)
# Change axis units from hours to seconds using the time_unit argument (default is "hours")
plot_signal(rec_dt, downsample_rate = 1, time_unit = "seconds")
# Modify transparency and add a custom plot title
plot_signal(rec_dt, downsample_rate = 1, time_unit = "seconds",
alpha = 1,
plot_title = "Recording 1 - Channel 1 - Alpha = 1")
This method will use ggplot2 via the gg_plot_signal()
function.
The downsample_rate
argument works exactly the same as in the interactive plot.
# Create a static plot and display it in the plot window
gg_plot_signal(rec_dt, downsample_rate = 1, alpha = 0.5)
# Assign the plot to a variable for further customization
p <- gg_plot_signal(rec_dt, downsample_rate = 1, alpha = 0.5)
# Segment plots to specific ranges by adding range and range_unit arguments ("hours" or "seconds")
# Plot hours 5-8 only
gg_plot_signal(rec_dt, downsample_rate = 1, alpha = 1, range = c(5, 8), range_unit = "hours")
# Plot from 12603.5 seconds to 12605.85 seconds
gg_plot_signal(rec_dt, alpha = 1,
downsample_rate = 1,
range = c(12603.5, 12605.85),
range_unit = "seconds")
# Save plots to disk using the output_file argument. If left blank, it defaults to NULL and displays the plot in the plot window
gg_plot_signal(
rec_dt,
alpha = 1,
downsample_rate = 1,
range = c(12603.5, 12605.85),
range_unit = "seconds",
plot_title = "12604-12606 seconds - Rec1 - Ch1",
output_file = "C:/Users/user/My_plot_file_folder/segmented_recording1_ch1_ggplot.svg"
)
- Load and Process: Quickly import
.DXX
files and prepare them for analysis. - Interactive Exploration: Zoom, pan, and explore waveforms for in-depth insights.
- Annotation: Add behavior-specific annotations to your plots.
- Customizable Outputs: Export high-quality, presentation-ready figures with vast control over appearance via ggplot2 and plotly.
For more details, visit the EPGplotR Documentation to explore tutorials, examples, and detailed instructions.
Want to contribute to EPGplotR? We welcome contributions! Check out our Contribution guidelines for this project for details on how to get started.
This project is licensed under the MIT License. See the LICENSE file for details.