View source: R/custom_legend_with_brackets.R
| draw_legend_with_brackets | R Documentation |
This function draws a completely custom legend outside of ggplot2's system, with vertical brackets showing comparisons.
draw_legend_with_brackets(
labels,
colors,
comparisons = NULL,
x = 0.1,
y = 0.9,
width = 0.2,
height = NULL,
title = NULL,
text_size = 10,
text_family = "sans",
text_face = "plain",
title_size = 11,
title_face = "bold",
sig_size = 11,
sig_face = "plain",
output_width = NULL,
output_height = NULL
)
labels |
Character vector of group names |
colors |
Character vector of colors for each group |
comparisons |
Data frame with columns: group1, group2, label |
x |
Numeric. X position of legend (0-1, in npc units) |
y |
Numeric. Y position of legend (0-1, in npc units) |
width |
Numeric. Width of legend box |
height |
Numeric. Height of legend box |
title |
Character. Legend title (optional) |
text_size |
Numeric. Font size for legend labels (default 10) |
text_family |
Character. Font family (e.g., "sans", "serif", "mono", "Helvetica", "Times") |
text_face |
Character. Font face: "plain", "bold", "italic", "bold.italic" (default "plain") |
title_size |
Numeric. Font size for title (default 11) |
title_face |
Character. Font face for title (default "bold") |
sig_size |
Numeric. Font size for significance symbols (default 11) |
sig_face |
Character. Font face for significance symbols (default "plain") |
output_width |
Numeric. Output figure width in inches (optional, for METHOD 2) |
output_height |
Numeric. Output figure height in inches (optional, for METHOD 2) |
A gTree object containing the custom legend
labels <- c("WT", "WT/Dox", "CH3+5")
colors <- c("green", "orange", "blue")
comps <- data.frame(group1 = "WT", group2 = "WT/Dox", label = "*")
legend_grob <- draw_legend_with_brackets(labels, colors, comps,
text_family = "sans",
text_size = 12)
grid::grid.draw(legend_grob)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.