Title: | Interactive Scatter Plot and Volcano Plot Labels |
---|---|
Description: | Interactive labelling of scatter plots, volcano plots and Manhattan plots using a 'shiny' and 'plotly' interface. Users can hover over points to see where specific points are located and click points on/off to easily label them. Labels can be dragged around the plot to place them optimally. Plots can be exported directly to PDF for publication. For plots with large numbers of points, points can optionally be rasterized as a bitmap, while all other elements (axes, text, labels & lines) are preserved as vector objects. This can dramatically reduce file size for plots with millions of points such as Manhattan plots, and is ideal for publication. |
Authors: | Myles Lewis [aut, cre] |
Maintainer: | Myles Lewis <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.3 |
Built: | 2025-02-06 20:23:31 UTC |
Source: | https://github.com/myles-lewis/easylabel |
Adds labels to a plotly 2d or 3d scatter plot. The labels can be dragged.
add_labels(p, labs, plotGlPixelRatio = 8)
add_labels(p, labs, plotGlPixelRatio = 8)
p |
A plotly scatter plot object |
labs |
Character vector of labels to match |
plotGlPixelRatio |
Integer passed to plotly.js config which controls pixel resolution of webGl rendering. Larger values increase resolution of points as well as file size. |
Labels are identified by searching the rownames of the embedded marker data within the plotly object. The plotly mode bar camera icon is set to export to svg by default.
A plotly plot with added labels
library(plotly) data(mtcars) p <- plot_ly(mtcars, x = ~mpg, y = ~wt, color = ~cyl, type = 'scatter', mode = 'markers') p %>% add_labels(c("Mazda RX4", "Fiat 128"))
library(plotly) data(mtcars) p <- plot_ly(mtcars, x = ~mpg, y = ~wt, color = ~cyl, type = 'scatter', mode = 'markers') p %>% add_labels(c("Mazda RX4", "Fiat 128"))
Change plotly font to Arial
arial(p, size = 14)
arial(p, size = 14)
p |
A plotly object |
size |
Font size |
A plotly object
library(plotly) data(mtcars) p <- plot_ly(mtcars, x = ~mpg, y = ~wt, color = ~cyl, type = 'scatter', mode = 'markers') p %>% arial p %>% arial(18)
library(plotly) data(mtcars) p <- plot_ly(mtcars, x = ~mpg, y = ~wt, color = ~cyl, type = 'scatter', mode = 'markers') p %>% arial p %>% arial(18)
Interactive labelling of scatter plots using shiny/plotly interface.
easylabel( data, x, y, labs = NULL, startLabels = NULL, start_xy = NULL, cex.text = 0.72, col = NULL, colScheme = NULL, alpha = 1, shape = NULL, shapeScheme = 21, size = 8, sizeRange = c(4, 80), xlab = x, ylab = y, xlim = NULL, ylim = NULL, xticks = NULL, yticks = NULL, showOutliers = TRUE, outlier_shape = 5, outline_col = "white", outline_lwd = 0.5, plotly_filter = NULL, width = 800, height = 600, showgrid = FALSE, zeroline = TRUE, hline = NULL, vline = NULL, mgp = c(1.8, 0.5, 0), Ltitle = "", Rtitle = "", LRtitle_side = 1, labelDir = "radial", labCentre = NULL, lineLength = 75, text_col = "black", line_col = "black", rectangles = FALSE, rect_col = "white", border_col = "black", padding = 3, border_radius = 5, showLegend = TRUE, legendxy = c(1.02, 1), filename = NULL, panel.last = NULL, fullGeneNames = FALSE, AnnotationDb = NULL, custom_annotation = NULL, output_shiny = TRUE, ... )
easylabel( data, x, y, labs = NULL, startLabels = NULL, start_xy = NULL, cex.text = 0.72, col = NULL, colScheme = NULL, alpha = 1, shape = NULL, shapeScheme = 21, size = 8, sizeRange = c(4, 80), xlab = x, ylab = y, xlim = NULL, ylim = NULL, xticks = NULL, yticks = NULL, showOutliers = TRUE, outlier_shape = 5, outline_col = "white", outline_lwd = 0.5, plotly_filter = NULL, width = 800, height = 600, showgrid = FALSE, zeroline = TRUE, hline = NULL, vline = NULL, mgp = c(1.8, 0.5, 0), Ltitle = "", Rtitle = "", LRtitle_side = 1, labelDir = "radial", labCentre = NULL, lineLength = 75, text_col = "black", line_col = "black", rectangles = FALSE, rect_col = "white", border_col = "black", padding = 3, border_radius = 5, showLegend = TRUE, legendxy = c(1.02, 1), filename = NULL, panel.last = NULL, fullGeneNames = FALSE, AnnotationDb = NULL, custom_annotation = NULL, output_shiny = TRUE, ... )
data |
Dataset (data.frame or data.table) to use for plot. |
x |
Specifies column of x coordinates in |
y |
Specifies column of y coordinates in |
labs |
Specifies the column in |
startLabels |
Vector of initial labels. With a character vector, labels
are identified in the column specified by |
start_xy |
List containing label annotation starting coordinates.
Invoked by |
cex.text |
Font size for labels. Default 0.72 to match plotly font size.
See |
col |
Specifies which column in |
colScheme |
A single colour or a vector of colours for points. |
alpha |
Alpha value for transparency of points. |
shape |
Specifies which column in |
shapeScheme |
A single symbol for points or a vector of symbols.
See |
size |
Either a single value for size of points (default 8), or
specifies which column in |
sizeRange |
Range of size of points for bubble charts. |
xlab |
x axis title. Accepts expressions when exporting base graphics.
Set |
ylab |
y axis title. Accepts expressions when exporting base graphics. |
xlim |
The x limits (x1, x2) of the plot. |
ylim |
The y limits of the plot. |
xticks |
List of custom x axis ticks and labels specified as a list of
two named vectors |
yticks |
List of custom y axis ticks and labels specified as a list of
two named vectors |
showOutliers |
Logical whether to show outliers on the margins of the plot. |
outlier_shape |
Symbol for outliers. |
outline_col |
Colour of symbol outlines. Set to |
outline_lwd |
Line width of symbol outlines. |
plotly_filter |
Refers to a column of logical values in |
width |
Width of the plot in pixels. Saving to pdf scales 100 pixels to 1 inch. |
height |
Height of the plot in pixels. |
showgrid |
Either logical whether to show gridlines, or a character value where "x" means showing x axis gridlines and "y" means showing y axis gridlines. |
zeroline |
Logical whether to show lines at x = 0 and y = 0. |
hline |
Adds horizontal lines at values of y. |
vline |
Adds vertical lines at values of x. |
mgp |
The margin line for the axis title, axis labels and axis line.
See |
Ltitle |
A character or expression (see plotmath) value specifying
text for left side title. Size of font can be changed using |
Rtitle |
A character or expression value specifying text for right side
title. Size of font can be changed using |
LRtitle_side |
On which side of the plot for |
labelDir |
Initial label line directions. Options include 'radial' (default) for radial lines around the centre of the plot, 'origin' for radial lines around the origin, 'horiz' for horizontal and 'vert' for vertical, 'xellipse' and 'yellipse' for near-horizontal and near-vertical lines arranged in an elliptical way around the centre, 'rect' for rectilinear lines (a mix of horizontal and vertical), 'x' for diagonal lines, 'oct' for lines in 8 directions around the centre. |
labCentre |
Coordinates in x/y units of the central point towards which radial labels converge. Defaults to the centre of the plot. |
lineLength |
Initial length of label lines in pixels. |
text_col |
Colour of label text. If set to
|
line_col |
Colour of label lines. If set to
|
rectangles |
Logical whether to show rectangles around labels (not supported by plotly). |
rect_col |
Colour for filling rectangles (not supported by plotly). If
set to |
border_col |
Colour of rectangle borders (not supported by plotly).
Use |
padding |
Amount of padding in pixels around label text. |
border_radius |
Amount of roundedness in pixels to apply to label rectangles (not supported by plotly). |
showLegend |
Logical whether to show or hide the legend. |
legendxy |
Vector of coordinates for the position of the legend.
Coordinates are in plotly paper reference with |
filename |
Filename for saving plots to pdf in a browser. Rstudio opens its own pdf file. |
panel.last |
An expression to be evaluated after plotting has taken place but before the axes, title and box are added. This can be useful for adding extra titles, legends or trend lines. Currently only works when saving plots using base graphics and does not work with plotly. See plot.default |
fullGeneNames |
Logical whether to expand gene symbols using
Bioconductor AnnotationDbi package. With multiple matches, returns first
value only.
See |
AnnotationDb |
Annotation database to use when expanding gene symbols.
Defaults to human gene database |
custom_annotation |
List of annotations to be added via
|
output_shiny |
Logical whether to output a shiny app. If |
... |
Further graphical parameters passed to |
Instructions:
Hover over and click on/off genes which you want to label.
When you have selected all your chosen genes, then drag gene names to move label positions.
Click the save button to export a PDF or other file types (SVG, jpeg, tiff, png) produced in base graphics. Files are saved to the browser downloads folder by default.
The Table tab shows a table view of the dataset to help with annotation.
The 'raster points' checkbox converts only the points to a raster which is embedded in pdf or svg exports, while the rest of the plot (axis/label lines/text etc) remain vectorised. This only applies when saving pdf or svg. For other file types the whole plot is rasterized as normal by base graphics.
For efficiency, the raster of the points is cached using the memoise
package. So if users change the labels or change from pdf to svg, the export
is much faster. If the resolution is changed the points will need to be
re-rasterized.
In the shiny interface the "Save state" button saves an rds file containing
the label positions and state of the plot as an 'easylab' S3 class object to
the current working directory. This can be reloaded in future sessions using
loadlabel()
.
By default no return value. If output_shiny = FALSE
or the shiny
button 'Export plotly & exit' is pressed, a plotly figure is returned.
easyVolcano()
, easyMAplot()
, easyManhattan()
, loadlabel()
# Simple example using mtcars dataset data(mtcars) # Launch easylabel Shiny app: only run this example in interactive R sessions if (interactive()) { easylabel(mtcars, x = 'mpg', y = 'wt', col = 'cyl') }
# Simple example using mtcars dataset data(mtcars) # Launch easylabel Shiny app: only run this example in interactive R sessions if (interactive()) { easylabel(mtcars, x = 'mpg', y = 'wt', col = 'cyl') }
Interactive labelling of Manhattan plots using 'shiny' and 'plotly' interface.
easyManhattan( data, chrom = "chrom", pos = "pos", p = "p", labs = "rsid", startLabels = NULL, pcutoff = 5e-08, chromGap = NULL, chromCols = c("royalblue", "skyblue"), sigCol = "red", alpha = 0.7, labelDir = "horiz", xlab = "Chromosome position", ylab = expression("-log"[10] ~ "P"), xlim = NULL, ylim = NULL, outline_col = NA, shapeScheme = 16, size = 6, width = ifelse(transpose, 600, 1000), height = ifelse(transpose, 800, 600), lineLength = 60, npoints = max(c(nrow(data)/5, 1e+06)), nplotly = 1e+05, npeaks = NULL, span = 2e+07, transpose = FALSE, filename = NULL, ... )
easyManhattan( data, chrom = "chrom", pos = "pos", p = "p", labs = "rsid", startLabels = NULL, pcutoff = 5e-08, chromGap = NULL, chromCols = c("royalblue", "skyblue"), sigCol = "red", alpha = 0.7, labelDir = "horiz", xlab = "Chromosome position", ylab = expression("-log"[10] ~ "P"), xlim = NULL, ylim = NULL, outline_col = NA, shapeScheme = 16, size = 6, width = ifelse(transpose, 600, 1000), height = ifelse(transpose, 800, 600), lineLength = 60, npoints = max(c(nrow(data)/5, 1e+06)), nplotly = 1e+05, npeaks = NULL, span = 2e+07, transpose = FALSE, filename = NULL, ... )
data |
The dataset (data.frame or data.table) for the plot. |
chrom |
The column of chomosome values in |
pos |
The column of SNP positions in |
p |
The column of p values in |
labs |
The column of labels in |
startLabels |
Vector of initial labels. With a character vector, labels
are identified in the column specified by |
pcutoff |
Cut-off for p value significance. Defaults to 5E-08. |
chromGap |
Size of gap between chromosomes along the x axis in base
pairs. If |
chromCols |
A vector of colours for points by chromosome. Colours are recycled dependent on the length of the vector. |
sigCol |
Colour for statistically significant points. Ignored if set to
|
alpha |
Transparency for points. |
labelDir |
Option for label lines. See |
xlab |
x axis title. Accepts expressions. |
ylab |
y axis title. Accepts expressions. |
xlim |
The x limits (x1, x2) of the plot. |
ylim |
The y limits of the plot. |
outline_col |
Colour of symbol outlines. Passed to |
shapeScheme |
A single symbol for points or a vector of symbols. Passed
to |
size |
Specifies point size. Passed to |
width |
Width of the plot in pixels. Saving to pdf scales 100 pixels to 1 inch. |
height |
Height of the plot in pixels. |
lineLength |
Initial length of label lines in pixels. |
npoints |
Maximum number of points to plot when saving the final plot to
pdf. By default plots with >1 million points are thinned to speed up
plotting. Setting a value of |
nplotly |
Maximum number of points to display via plotly. We recommend the default setting of 100,000 points (or fewer). |
npeaks |
Number of peaks to label initially. |
span |
a peak is defined as the most significant SNP within a window of width span centred at that SNP. |
transpose |
Logical whether to transpose the plot. |
filename |
Filename for saving to pdf. |
... |
Other arguments passed to |
By default no return value. If output_shiny = FALSE
or the shiny
button 'Export plotly & exit' is pressed, a plotly figure is returned.
See easylabel()
.
Interactive labelling of MA plots using shiny/plotly interface.
easyMAplot( data, x = NULL, y = NULL, padj = NULL, fdrcutoff = 0.05, colScheme = c("darkgrey", "blue", "red"), hline = 0, labelDir = "yellipse", xlab = expression("log"[2] ~ " mean expression"), ylab = expression("log"[2] ~ " fold change"), filename = NULL, showCounts = TRUE, useQ = FALSE, ... )
easyMAplot( data, x = NULL, y = NULL, padj = NULL, fdrcutoff = 0.05, colScheme = c("darkgrey", "blue", "red"), hline = 0, labelDir = "yellipse", xlab = expression("log"[2] ~ " mean expression"), ylab = expression("log"[2] ~ " fold change"), filename = NULL, showCounts = TRUE, useQ = FALSE, ... )
data |
The dataset for the plot. Automatically attempts to recognises DESeq2 and limma objects. |
x |
Name of the column containing mean expression. For DESeq2 and limma objects this is automatically set. |
y |
Name of the column containing log fold change. For DESeq2 and limma objects this is automatically set. |
padj |
Name of the column containing adjusted p values (optional). For DESeq2 and
limma objects this is automatically set. If |
fdrcutoff |
Cut-off for FDR significance. Defaults to FDR < 0.05. Can
be vector with multiple cut-offs. To use nominal P values instead of adjusted
p values, set |
colScheme |
Colour colScheme. Length must match either length(fdrcutoff) + 1 to allow for non-significant genes, or match length(fdrcutoff) * 2 + 1 to accommodates asymmetric colour colSchemes for positive & negative fold change. (see examples). |
hline |
Vector of horizontal lines (default is y = 0). |
labelDir |
Option for label lines. See |
xlab |
x axis title. Accepts expressions. |
ylab |
y axis title. Accepts expressions. |
filename |
Filename for saving to pdf. |
showCounts |
Logical whether to show legend with number of differentially expressed genes. |
useQ |
Logical whether to convert nominal P values to q values. Requires the qvalue Bioconductor package. |
... |
Other arguments passed to |
By default no return value. If output_shiny = FALSE
or the shiny
button 'Export plotly & exit' is pressed, a plotly figure is returned.
See easylabel()
.
Interactive labelling of volcano plots using shiny/plotly interface.
easyVolcano( data, x = NULL, y = NULL, padj = y, fdrcutoff = 0.05, fccut = NULL, colScheme = c("darkgrey", "blue", "red"), xlab = expression("log"[2] ~ " fold change"), ylab = expression("-log"[10] ~ " P"), filename = NULL, showCounts = TRUE, useQ = FALSE, ... )
easyVolcano( data, x = NULL, y = NULL, padj = y, fdrcutoff = 0.05, fccut = NULL, colScheme = c("darkgrey", "blue", "red"), xlab = expression("log"[2] ~ " fold change"), ylab = expression("-log"[10] ~ " P"), filename = NULL, showCounts = TRUE, useQ = FALSE, ... )
data |
The dataset for the plot. Automatically attempts to recognises DESeq2 and limma objects. |
x |
Name of the column containing log fold change. For DESeq2 and limma objects this is automatically set. |
y |
Name of the column containing p values. For DESeq2 and limma objects this is automatically set. |
padj |
Name of the column containing adjusted p values (optional). If
|
fdrcutoff |
Cut-off for FDR significance. Defaults to FDR < 0.05. If |
fccut |
Optional vector of log fold change cut-offs. |
colScheme |
Colour scheme. If no fold change cut-off is set, 2 colours need to be specified. With a single fold change cut-off, 3 or 5 colours are required, depending on whether the colours are symmetrical about x = 0. Accommodates asymmetric colour schemes with multiple fold change cut-offs (see examples). |
xlab |
x axis title. Accepts expressions. |
ylab |
y axis title. Accepts expressions. |
filename |
Filename for saving to pdf. |
showCounts |
Logical whether to show legend with number of differentially expressed genes. |
useQ |
Logical whether to convert nominal P values to q values. Requires the qvalue Bioconductor package. |
... |
Other arguments passed to |
By default no return value. If output_shiny = FALSE
or the shiny
button 'Export plotly & exit' is pressed, a plotly figure is returned.
See easylabel()
.
Produces a QQ plot via ggplot2. Requires a dataframe generated by
qqplot()
.
gg_qqplot(df, scheme = c("darkgrey", "royalblue"))
gg_qqplot(df, scheme = c("darkgrey", "royalblue"))
df |
A dataframe generated by |
scheme |
Vector of 2 colours for plotting non-significant and significant SNPs |
A ggplot2 graphics plot object
Loads a file or easylab object containing saved state with specified labels and their positions.
loadlabel(object, data = NULL, ...)
loadlabel(object, data = NULL, ...)
object |
Either a character value specifying an rds file to be loaded, or an object of class 'easylab'. |
data |
Dataset (data.frame or data.table) to use for plot. If not
specified, the function will first use embedded data included in |
... |
Additional arguments passed to |
By default no return value. Calls easylabel()
which will open a
shiny interactive session based on previous settings stored in an 'easylab'
class object or rds file of such an object.
Fast function for generating a log quantile-quantile (QQ) p-value plot
qqplot( pval, fdr = NULL, fdr_cutoff = 0.05, scheme = c("darkgrey", "royalblue"), npoints = 5e+05, show_plot = TRUE, verbose = TRUE, ... )
qqplot( pval, fdr = NULL, fdr_cutoff = 0.05, scheme = c("darkgrey", "royalblue"), npoints = 5e+05, show_plot = TRUE, verbose = TRUE, ... )
pval |
A vector of p-values |
fdr |
An optional vector of FDR values to save time if previously
computed. If not supplied, these will be calculated using |
fdr_cutoff |
Cutoff for FDR significance |
scheme |
Vector of 2 colours for plotting non-significant and significant SNPs |
npoints |
Limits the number of non-significant points being plotted to
speed up plotting. See details. Set to |
show_plot |
Logical whether to produce a plot via base graphics or just return dataframe ready for plotting. |
verbose |
Whether to show messages |
... |
Optional plotting arguments passed to |
Produces a fast QQ plot. Particularly useful for analyses with very large
numbers of p-values (such as eQTL analysis) which can be slow to plot. The
function looks first for all comparisons which reached FDR at the designated
cut-off and ensures all of these points are plotted. Additional points which
typically overlap substantially near the origin are thinned by random
sampling. In this way the plot can be reduced from millions of points to
500,000 points with a plot which is indistinguishable from one with all
points plotted. For comparison, set npoints
to NULL
to plot all points as
usual.
Calling qqplot()
will result in a base graphics plot. The plotting
dataframe is returned invisibly, so users can save time when refining plots
by saving the dataframe produced by qqplot()
and then invoking qqplot2()
to simply plot the points. Users who prefer ggplot2 can also pass the
dataframe generated by qqplot()
to gg_qqplot()
.
Generates a plot using base graphics. Also returns a dataframe
invisibly which can be used for downstream plotting via either qqplot2()
or gg_qqplot()
.
Second stage plotting function which accepts dataframe generated by
qqplot()
. This can be used to avoid repeating computation of the QQ plot
values.
qqplot2(df, scheme = c("darkgrey", "royalblue"), ...)
qqplot2(df, scheme = c("darkgrey", "royalblue"), ...)
df |
A dataframe generated by |
scheme |
Vector of 2 colours for plotting non-significant and significant SNPs |
... |
Optional plotting arguments passed to |
No return value. Produces a base graphics plot.
Prints summary information on an easylabel saved state object.
## S3 method for class 'easylab' summary(object, ...)
## S3 method for class 'easylab' summary(object, ...)
object |
Object of class 'easylab' |
... |
Optional arguments for compatibility |
No return value. Prints information on the original easylabel call and saved labels.
Example DESeq2 volcano data for vignette
volc1
volc1
Data frame with 6 rows and 6 variables
Example limma volcano data for vignette
volc2
volc2
Data frame with 6 rows and 6 variables