Title: | A 'ggplot2' Extension Inspired by 'GraphPad Prism' |
Version: | 1.0.6 |
Description: | Provides various themes, palettes, and other functions that are used to customise ggplots to look like they were made in 'GraphPad Prism'. The 'Prism'-look is achieved with theme_prism() and scale_fill|colour_prism(), axes can be changed with custom guides like guide_prism_minor(), and significance indicators added with add_pvalue(). |
License: | GPL (≥ 3.0) |
URL: | https://csdaw.github.io/ggprism/, https://github.com/csdaw/ggprism |
BugReports: | https://github.com/csdaw/ggprism/issues |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.3.2 |
Depends: | R (≥ 3.2) |
Imports: | digest, ggplot2 (≥ 3.2.0), glue, grid, gtable (≥ 0.1.1), rlang (≥ 0.3.0), scales (≥ 0.5.0), stats, tibble, utils |
Suggests: | covr, dplyr, ggbeeswarm, ggnewscale, knitr, magrittr, patchwork, rmarkdown, rstatix, tidyr, tinytest |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2025-05-17 10:19:04 UTC; csd51 |
Author: | Charlotte Dawson |
Maintainer: | Charlotte Dawson <csdaw@outlook.com> |
Repository: | CRAN |
Date/Publication: | 2025-05-17 10:50:02 UTC |
ggprism: A 'ggplot2' Extension Inspired by 'GraphPad Prism'
Description
Provides various themes, palettes, and other functions that are used to customise ggplots to look like they were made in 'GraphPad Prism'. The 'Prism'-look is achieved with theme_prism() and scale_fill|colour_prism(), axes can be changed with custom guides like guide_prism_minor(), and significance indicators added with add_pvalue().
Author(s)
Maintainer: Charlotte Dawson csdaw@outlook.com (ORCID)
See Also
Useful links:
Report bugs at https://github.com/csdaw/ggprism/issues
ggproto classes for ggprism
Description
ggproto classes for ggprism
Usage
StatBracket
GeomBracket
Format
An object of class StatBracket
(inherits from Stat
, ggproto
, gg
) of length 4.
An object of class GeomBracket
(inherits from Geom
, ggproto
, gg
) of length 5.
Add p-values to a ggplot
Description
Add p-values with or without brackets to a ggplot.
See here or the examples section below for examples of how to use.
add_pvalue
is a refactored version of
stat_pvalue_manual
from
kassambara/ggpubr, altered to
have less dependencies, and more flexibility with input format and
aesthetics. Any examples using stat_pvalue_manual
found on
Datanovia
will also work with add_pvalue
.
Usage
add_pvalue(
data,
label = NULL,
xmin = "group1",
xmax = "group2",
x = NULL,
y.position = "y.position",
parse = FALSE,
label.size = 3.2,
colour = NULL,
color = NULL,
tip.length = 0.03,
bracket.size = 0.6,
bracket.colour = NULL,
bracket.color = NULL,
bracket.shorten = 0,
bracket.nudge.y = 0,
step.increase = 0,
step.group.by = NULL,
remove.bracket = FALSE,
coord.flip = FALSE,
position = "identity",
...
)
Arguments
data |
A |
label |
|
xmin |
|
xmax |
Optional. |
x |
|
y.position |
|
parse |
|
label.size |
|
colour , color |
|
tip.length |
|
bracket.size |
|
bracket.colour , bracket.color |
|
bracket.shorten |
|
bracket.nudge.y |
|
step.increase |
|
step.group.by |
|
remove.bracket |
|
coord.flip |
|
position |
|
... |
Additional aesthetics or arguments passed to
|
Value
Returns a layer ggproto object with either geom = GeomBracket
or
geom = GeomText
.
Allowed ... values
add_pvalue
understands the following additional aesthetics or arguments:
fontface
string
. Fontface of text (e.g."bold"
).fontfamily
string
. Fontfamily of text (e.g."Arial"
).hjust
numeric
. Horizontal justification of text.vjust
numeric
. Vertical justification of text.alpha
numeric
. Transparency of text and/or brackets.linetype
string
ornumeric
. Linetype of brackets (e.g."dashed"
).lineend
string
. Lineend of brackets (e.g."butt"
).na.rm
logical
. IfFALSE
(default), removes missing values with a warning. IfTRUE
silently removes missing values.show.legend
logical
. Should this layer be included in the legends? IfNA
(default), include if any aesthetics are mapped. IfFALSE
, never include or ifTRUE
, always include. It can also be a namedlogical
vector to finely select the aesthetics to display.inherit.aes
logical
. IfFALSE
, overrides the default aesthetics, rather than combining with them.
Examples
library(ggplot2)
## we will use the ToothGrowth dataset for all examples
tg <- ToothGrowth
tg$dose <- as.factor(tg$dose)
tg$group <- factor(rep(c("grp1", "grp2"), 30))
## p-value bracket comparing two means
# p-value table (its best to use these column names)
two.means <- tibble::tribble(
~group1, ~group2, ~p, ~y.position,
"OJ", "VC", 0.0606, 36
)
# boxplot (or another geom...)
ggplot(tg, aes(x = supp, y = len)) +
geom_boxplot() +
add_pvalue(two.means)
# if your table has special column names you will need to specify them
two.means <- tibble::tribble(
~apple, ~banana, ~my.pval, ~some.y.position,
"OJ", "VC", 0.0606, 36
)
ggplot(tg, aes(x = supp, y = len)) +
geom_boxplot() +
add_pvalue(
two.means,
xmin = "apple",
xmax = "banana",
label = "my.pval",
y.position = "some.y.position"
)
## you can make the label a glue expression
two.means <- tibble::tribble(
~group1, ~group2, ~p, ~y.position,
"OJ", "VC", 0.0606, 36
)
ggplot(tg, aes(x = supp, y = len)) +
geom_boxplot() +
add_pvalue(two.means, label = "p = {p}")
## you can change aesthetics of the bracket and label
ggplot(tg, aes(x = supp, y = len)) +
geom_boxplot() +
add_pvalue(
two.means,
label = "p = {p}",
colour = "red", # label
label.size = 6, # label
fontface = "bold", # label
fontfamily = "serif", # label
angle = 45, # label
bracket.colour = "blue", # bracket
bracket.size = 1, # bracket
linetype = "dashed", # bracket
lineend = "round" # bracket
)
## you can change the tip length of the bracket
# make them longer
ggplot(tg, aes(x = supp, y = len)) +
geom_boxplot() +
add_pvalue(two.means, tip.length = 0.1)
# make them disappear
ggplot(tg, aes(x = supp, y = len)) +
geom_boxplot() +
add_pvalue(two.means, tip.length = 0)
# make one side longer than the other
ggplot(tg, aes(x = supp, y = len)) +
geom_boxplot() +
add_pvalue(two.means, tip.length = c(0.1, 0))
## p-value brackets with comparisons to a reference sample
each.vs.ref <- tibble::tribble(
~group1, ~group2, ~p.adj, ~y.position,
"0.5", "1", 8.80e-14, 35,
"0.5", "2", 1.27e-7, 38
)
ggplot(tg, aes(x = dose, y = len)) +
geom_boxplot(aes(fill = dose)) +
add_pvalue(each.vs.ref)
## p-value brackets with pairwise comparisons
pairwise <- tibble::tribble(
~group1, ~group2, ~p.signif, ~y.position,
"0.5", "1", "****", 38,
"0.5", "2", "****", 36,
"1", "2", "****", 38
)
# you can shorten the length of brackets that are close together
ggplot(tg, aes(x = dose, y = len)) +
geom_boxplot(aes(fill = dose)) +
add_pvalue(
pairwise,
bracket.shorten = c(0.05, 0, 0.05)
)
# you can nudge brackets that are not quite in the correct y position
# instead of changing the p-value table
ggplot(tg, aes(x = dose, y = len)) +
geom_boxplot(aes(fill = dose)) +
add_pvalue(
pairwise,
bracket.shorten = c(0.05, 0, 0.05),
bracket.nudge.y = c(0.5, 0, 0.5)
)
## p-value brackets with pairwise comparisons of grouped data
pairwise.grouped <- tibble::tribble(
~group1, ~group2, ~p.adj, ~y.position, ~supp,
"0.5", "1", 2.63e-4, 33.5, "OJ",
"0.5", "2", 3.96e-6, 37.6, "OJ",
"1", "2", 1.18e-1, 41.6, "OJ",
"0.5", "1", 2.04e-6, 36.5, "VC",
"0.5", "2", 1.40e-7, 40.6, "VC",
"1", "2", 2.75e-4, 44.6, "VC"
)
# use step.increase to change the spacing between different brackets in the
# groups specified by step.group.by
ggplot(tg, aes(x = dose, y = len)) +
geom_boxplot(aes(fill = supp)) +
add_pvalue(
pairwise.grouped,
colour = "supp",
tip.length = 0,
step.group.by = "supp",
step.increase = 0.03
)
## p-value (brackets) with single facet variable
two.means.grouped1 <- tibble::tribble(
~group1, ~group2, ~p.adj, ~y.position, ~dose,
"OJ", "VC", 0.0127, 24, "0.5",
"OJ", "VC", 0.00312, 30, "1",
"OJ", "VC", 0.964, 36.5, "2"
)
ggplot(tg, aes(x = supp, y = len)) +
geom_boxplot() +
facet_wrap(~ dose, scales = "free") +
add_pvalue(two.means.grouped1) # table must have dose column
## p-value (brackets) with single facet variable and multiple brackets per facet
pairwise.grouped <- tibble::tribble(
~group1, ~group2, ~p.adj, ~y.position, ~supp,
"0.5", "1", 2.63e-4, 33.5, "OJ",
"0.5", "2", 3.96e-6, 37.6, "OJ",
"1", "2", 1.18e-1, 41.6, "OJ",
"0.5", "1", 2.04e-6, 36.5, "VC",
"0.5", "2", 1.40e-7, 40.6, "VC",
"1", "2", 2.75e-4, 44.6, "VC"
)
ggplot(tg, aes(x = dose, y = len)) +
geom_boxplot(aes(fill = supp)) +
facet_wrap(~ supp) +
add_pvalue(pairwise.grouped)
## p-value (brackets) with two facet variables
two.means.grouped2 <- tibble::tribble(
~group1, ~group2, ~p.signif, ~y.position, ~group, ~dose,
"OJ", "VC", "*", 21, "grp1", "0.5",
"OJ", "VC", "**", 30, "grp2", "1"
)
ggplot(tg, aes(x = supp, y = len)) +
geom_boxplot() +
facet_wrap(group ~ dose) +
add_pvalue(two.means.grouped2) # table must have dose and group column
## p-value (text only) comparing two means
two.means <- tibble::tribble(
~group1, ~group2, ~p, ~y.position,
"OJ", "VC", 0.0606, 36
)
ggplot(tg, aes(x = supp, y = len)) +
geom_boxplot() +
add_pvalue(two.means, remove.bracket = TRUE, x = 1.5)
## p-value (text only) with coord_flip, override y.position, change angle
ggplot(tg, aes(x = supp, y = len)) +
geom_boxplot() +
add_pvalue(
two.means,
remove.bracket = TRUE,
x = 1.5,
y.position = 32,
angle = 45
) +
coord_flip()
## p-value (text only) comparing to the null
one.mean <- tibble::tribble(
~group1, ~group2, ~p.signif, ~y.position, ~dose,
"1", "null model", "****", 35, "0.5",
"1", "null model", "****", 35, "1",
"1", "null model", "****", 35, "2"
)
ggplot(tg, aes(x = dose, y = len)) +
geom_boxplot(aes(fill = dose)) +
add_pvalue(one.mean, x = "dose")
## p-value (text only) with comparisons to a base mean
each.vs.basemean <- tibble::tribble(
~group1, ~group2, ~p.adj, ~y.position,
"all", "0.5", "****", 35,
"all", "1", "ns", 35,
"all", "2", "****", 35
)
ggplot(tg, aes(x = dose, y = len)) +
geom_boxplot(aes(fill = dose)) +
add_pvalue(each.vs.basemean)
## p-value (text only) with comparison to reference sample
each.vs.ref <- tibble::tribble(
~group1, ~group2, ~p.adj, ~y.position,
"0.5", "1", 8.80e-14, 35,
"0.5", "2", 1.27e-7, 38
)
ggplot(tg, aes(x = dose, y = len)) +
geom_boxplot(aes(fill = dose)) +
add_pvalue(each.vs.ref, coord.flip = TRUE, remove.bracket = TRUE)
## p-value (text only) with a grouping variable
two.means.grouped1 <- tibble::tribble(
~group1, ~group2, ~p.adj, ~y.position, ~dose,
"OJ", "VC", 0.0127, 24, "0.5",
"OJ", "VC", 0.00312, 30, "1",
"OJ", "VC", 0.964, 36.5, "2"
)
ggplot(tg, aes(x = dose, y = len)) +
geom_boxplot(aes(fill = supp)) +
add_pvalue(two.means.grouped1, x = "dose")
Add ticks as ggplot annotation
Description
This is an annotation function to add tick marks (major, minor, or both) to
a ggplot. Clipping must be turned off if the ticks are to appear outside the
plotting area, for example with: coord_cartesian(clip = "off")
.
Usage
annotation_ticks(
sides = "b",
type = "both",
outside = FALSE,
tick.length = unit(4.8, "pt"),
minor.length = unit(2.4, "pt"),
linewidth = 0.6,
colour = "black",
color = NULL,
linetype = 1,
lineend = "butt",
alpha = 1,
data = data.frame(x = NA)
)
Arguments
sides |
|
type |
|
outside |
|
tick.length |
a |
minor.length |
a |
linewidth |
|
colour , color |
|
linetype |
|
lineend |
|
alpha |
|
data |
|
Value
Returns a layer ggproto object with geom = GeomTicks
.
Source
The code is a slightly modified version of the answer to this
Stack Overflow question 58485334,
which is itself a refactored version of this
annotation_ticks()
function.
Examples
## Generally it is better to use the guide_prism_minor function.
## However annotation_ticks is useful in a few specific situations.
library(ggplot2)
## easily put ticks without labels around a plot with a border
ggplot(mtcars, aes(x = mpg, y = disp)) +
geom_point() +
theme_prism(border = TRUE) +
coord_cartesian(clip = "off") +
annotation_ticks(sides = "tr", type = "major", outside = TRUE) +
theme(plot.margin = unit(c(4, 4, 4, 4), "mm"))
# the same but with minor ticks as well
ggplot(mtcars, aes(x = mpg, y = disp)) +
geom_point() +
scale_x_continuous(guide = "prism_minor") +
scale_y_continuous(guide = "prism_minor") +
theme_prism(border = TRUE) +
coord_cartesian(clip = "off") +
annotation_ticks(sides = "tr", type = "both", outside = TRUE) +
theme(plot.margin = unit(c(4, 4, 4, 4), "mm"))
# you can adjust the appearance of annotation_ticks
ggplot(mtcars, aes(x = mpg, y = disp)) +
geom_point() +
theme_prism(border = TRUE) +
coord_cartesian(clip = "off") +
annotation_ticks(
sides = "tr",
type = "major",
outside = TRUE,
tick.length = unit(10, "pt"),
colour = "red",
linewidth = 2,
linetype = "dashed",
lineend = "round"
) +
theme(plot.margin = unit(c(4, 4, 4, 4), "mm"))
## Unfortunately, due to the way they work, secondary axes don't always play
## well with the minor tick axes guides in this package.
## So we can use annotation_ticks instead.
sample.data <- data.frame(
day = as.Date("2019-01-01") + 0:99,
temperature = runif(100) + seq(1, 100)^2.5 / 10000,
price = runif(100) + seq(100, 1)^1.5 / 10
)
# sample graph with secondary axis
ggplot(sample.data, aes(x = day)) +
geom_line(aes(y = temperature), colour = "magenta") +
geom_line(aes(y = price / 10), colour = "blue") +
scale_y_continuous(sec.axis = sec_axis(~. * 10, name = "price")) +
theme_prism(border = TRUE) +
coord_cartesian(clip = "off")
# guide_prism_minor only works with the main axis in this case
ggplot(sample.data, aes(x = day)) +
geom_line(aes(y = temperature), colour = "magenta") +
geom_line(aes(y = price / 10), colour = "blue") +
scale_y_continuous(
sec.axis = sec_axis(~. * 10, name = "price"),
guide = "prism_minor"
) +
theme_prism(border = TRUE) +
coord_cartesian(clip = "off")
# we use annotation_ticks to draw the minor ticks on the secondary axis
ggplot(sample.data, aes(x = day)) +
geom_line(aes(y = temperature), colour = "magenta") +
geom_line(aes(y = price / 10), colour = "blue") +
scale_y_continuous(
sec.axis = sec_axis(~. * 10, name = "price"),
guide = "prism_minor"
) +
theme_prism(border = TRUE) +
coord_cartesian(clip = "off") +
annotation_ticks(sides = "r", type = "minor", outside = TRUE)
Grob for bracket axes
Description
Grob for bracket axes.
Usage
draw_prism_bracket(
break_positions,
break_labels,
axis_position,
theme,
check.overlap = FALSE,
angle = NULL,
n.dodge = 1,
width = NULL,
outside = TRUE
)
Arguments
break_positions |
Position of bracket center and labels |
break_labels |
Labels between ticks |
axis_position |
Position of axis (top, bottom, left or right) |
theme |
A complete |
check.overlap |
Silently remove overlapping labels, (recursively) prioritizing the first, last, and middle labels. |
angle |
Compared to setting the angle in
|
n.dodge |
The number of rows (for vertical axes) or columns (for horizontal axes) that should be used to render the labels. This is useful for displaying labels that would otherwise overlap. |
width |
|
outside |
|
Grob for axes with minor ticks
Description
Grob for axes with minor ticks
Usage
draw_prism_minor(
break_positions,
break_labels,
breaks_major,
axis_position,
theme,
check.overlap = FALSE,
angle = NULL,
n.dodge = 1
)
Arguments
break_positions |
position of ticks |
break_labels |
labels at ticks |
breaks_major |
logical vector indicating major ticks versus minor ticks |
axis_position |
position of axis (top, bottom, left or right) |
theme |
A complete |
check.overlap |
silently remove overlapping labels, (recursively) prioritizing the first, last, and middle labels. |
angle |
Compared to setting the angle in
|
n.dodge |
The number of rows (for vertical axes) or columns (for horizontal axes) that should be used to render the labels. This is useful for displaying labels that would otherwise overlap. |
Grob for offset axes
Description
Grob for offset axes
Usage
draw_prism_offset(
break_positions,
break_labels,
axis_position,
theme,
check.overlap = FALSE,
angle = NULL,
n.dodge = 1
)
Arguments
break_positions |
position of ticks |
break_labels |
labels at ticks |
axis_position |
position of axis (top, bottom, left or right) |
theme |
A complete |
check.overlap |
silently remove overlapping labels, (recursively) prioritizing the first, last, and middle labels. |
angle |
Compared to setting the angle in
|
n.dodge |
The number of rows (for vertical axes) or columns (for horizontal axes) that should be used to render the labels. This is useful for displaying labels that would otherwise overlap. |
Grob for offset axes with minor ticks
Description
Grob for offset axes with minor ticks
Usage
draw_prism_offset_minor(
break_positions,
break_labels,
breaks_major,
axis_position,
theme,
check.overlap = FALSE,
angle = NULL,
n.dodge = 1
)
Arguments
break_positions |
position of ticks |
break_labels |
labels at ticks |
breaks_major |
logical vector indicating major ticks versus minor ticks |
axis_position |
position of axis (top, bottom, left or right) |
theme |
A complete |
check.overlap |
silently remove overlapping labels, (recursively) prioritizing the first, last, and middle labels. |
angle |
Compared to setting the angle in
|
n.dodge |
The number of rows (for vertical axes) or columns (for horizontal axes) that should be used to render the labels. This is useful for displaying labels that would otherwise overlap. |
Palettes and theme data for ggprism
Description
This list object contains the strings and values used in ggprism themes and palettes.
Usage
ggprism_data
Format
An object of class list
of length 4.
Axis guide with brackets
Description
This guide turns the axis into brackets drawn around each axis label.
Usage
guide_prism_bracket(
title = waiver(),
check.overlap = FALSE,
angle = NULL,
n.dodge = 1,
order = 0,
position = waiver(),
width = NULL,
outside = TRUE
)
Arguments
title |
A character string or expression indicating a title of guide.
If |
check.overlap |
silently remove overlapping labels, (recursively) prioritizing the first, last, and middle labels. |
angle |
Compared to setting the angle in
|
n.dodge |
The number of rows (for vertical axes) or columns (for horizontal axes) that should be used to render the labels. This is useful for displaying labels that would otherwise overlap. |
order |
A positive |
position |
Where this guide should be drawn: one of top, bottom, left, or right. |
width |
|
outside |
|
Details
The number of brackets can be adjusted using the breaks
argument in scale_(x|y)_continuous()
or scale_(x|y)_discrete()
.
Value
Returns a prism_bracket guide class object.
Examples
library(ggplot2)
## base plot
base <- ggplot(mpg, aes(x = as.factor(cyl), y = hwy)) +
geom_jitter(width = 0.2) +
theme(axis.line = element_line(colour = "black"))
## use brackets on x axis
# if not specified, the width of the brackets is guessed
base + scale_x_discrete(guide = "prism_bracket")
# you can add brackets using the guide function as well
base + guides(x = "prism_bracket")
## works with coord_flip
base + scale_x_discrete(guide = "prism_bracket") +
coord_flip()
## adjust bracket width
base + scale_x_discrete(guide = guide_prism_bracket(width = 0.12))
## make brackets point inward
base + scale_x_discrete(guide = guide_prism_bracket(width = 0.12, outside = FALSE))
## change colour with the usual axis.line, axis.ticks, axis.text elements
base + scale_x_discrete(guide = guide_prism_bracket(width = 0.12, outside = FALSE)) +
theme(axis.line.x = element_line(colour = "red"),
axis.ticks.x = element_line(colour = "blue"),
axis.text.x = element_text(colour = "green"))
Axis guide with minor ticks
Description
This guide is like the standard guide_axis
, but
with minor ticks.
Usage
guide_prism_minor(
title = waiver(),
check.overlap = FALSE,
angle = NULL,
n.dodge = 1,
order = 0,
position = waiver()
)
Arguments
title |
A character string or expression indicating a title of guide.
If |
check.overlap |
silently remove overlapping labels, (recursively) prioritizing the first, last, and middle labels. |
angle |
Compared to setting the angle in
|
n.dodge |
The number of rows (for vertical axes) or columns (for horizontal axes) that should be used to render the labels. This is useful for displaying labels that would otherwise overlap. |
order |
A positive |
position |
Where this guide should be drawn: one of top, bottom, left, or right. |
Details
The number of minor ticks can be changed using the minor_breaks
argument. Control the length of minor ticks by setting
prism.ticks.length
to a unit
object using
theme
, for example:
prism.ticks.length = unit(2, "pt")
. The major tick lengths
are adjusted using the standard axis.ticks.length
.
Value
Returns a prism_minor guide class object.
Examples
library(ggplot2)
## base plot
base <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point()
## add minor ticks to x and y axes
base +
scale_x_continuous(
limits = c(0, 6),
guide = "prism_minor"
) +
scale_y_continuous(
limits = c(10, 35),
guide = "prism_minor"
)
## you can also use the guides function to add minor ticks
base +
guides(x = "prism_minor", y = "prism_minor")
## adjust number of minor ticks by adjusting minor breaks
base +
scale_x_continuous(
limits = c(0, 6),
minor_breaks = seq(0, 6, 0.5),
guide = "prism_minor"
) +
scale_y_continuous(
limits = c(10, 35),
minor_breaks = seq(10, 35, 1.25),
guide = "prism_minor"
)
## adjust the length of major ticks with the usual axis.ticks.length element
base +
scale_x_continuous(
limits = c(0, 6),
minor_breaks = seq(0, 6, 0.5),
guide = "prism_minor"
) +
scale_y_continuous(
limits = c(10, 35),
minor_breaks = seq(10, 35, 1.25),
guide = "prism_minor"
) +
theme(
axis.ticks.length = unit(10, "pt")
)
## adjust the length of minor ticks with a new prism.ticks.length element
base +
scale_x_continuous(
limits = c(0, 6),
minor_breaks = seq(0, 6, 0.5),
guide = "prism_minor"
) +
scale_y_continuous(
limits = c(10, 35),
minor_breaks = seq(10, 35, 1.25),
guide = "prism_minor"
) +
theme(
axis.ticks.length = unit(10, "pt"),
prism.ticks.length = unit(5, "pt")
)
## to get log10 minor ticks just use a log10 scale and set the minor breaks
ggplot(msleep, aes(bodywt, brainwt)) +
geom_point(na.rm = TRUE) +
scale_x_log10(limits = c(1e0, 1e4),
minor_breaks = rep(1:9, 4)*(10^rep(0:3, each = 9)),
guide = "prism_minor")
## change colour with the usual axis.ticks element
base +
scale_x_continuous(
limits = c(0, 6),
minor_breaks = seq(0, 6, 0.5),
guide = "prism_minor"
) +
scale_y_continuous(
limits = c(10, 35),
minor_breaks = seq(10, 35, 1.25),
guide = "prism_minor"
) +
theme(
axis.ticks.length = unit(10, "pt"),
prism.ticks.length = unit(5, "pt"),
axis.ticks = element_line(colour = "red")
)
Offset axis guide
Description
This guide draws the axis only as wide as the outermost tick marks, similar to offset axes from Prism.
Usage
guide_prism_offset(
title = waiver(),
check.overlap = FALSE,
angle = NULL,
n.dodge = 1,
order = 0,
position = waiver()
)
Arguments
title |
A character string or expression indicating a title of guide.
If |
check.overlap |
silently remove overlapping labels, (recursively) prioritizing the first, last, and middle labels. |
angle |
Compared to setting the angle in
|
n.dodge |
The number of rows (for vertical axes) or columns (for horizontal axes) that should be used to render the labels. This is useful for displaying labels that would otherwise overlap. |
order |
A positive |
position |
Where this guide should be drawn: one of top, bottom, left, or right. |
Details
Control the length of the axis by adjusting the breaks
argument in
scale_(x|y)_continuous()
or scale_(x|y)_discrete()
.
Value
Returns a prism_offset guide class object.
Examples
library(ggplot2)
## base plot
base <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
theme(axis.line = element_line(colour = "black"))
## use offset guide via scale_x/y_continuous
base +
scale_x_continuous(
limits = c(1, 6),
breaks = seq(1, 6, by = 1),
guide = "prism_offset"
) +
scale_y_continuous(
guide = "prism_offset"
)
## use offset guide via guides argument
base +
guides(x = "prism_offset", y = "prism_offset") +
scale_x_continuous(
limits = c(1, 6),
breaks = seq(1, 6, by = 1)
)
## change colour and tick length with the usual elements
base +
scale_x_continuous(
limits = c(0, 6),
minor_breaks = seq(0, 6, 0.5),
guide = "prism_offset"
) +
scale_y_continuous(
limits = c(10, 35),
minor_breaks = seq(10, 35, 1.25),
guide = "prism_offset"
) +
theme(
axis.ticks.length = unit(10, "pt"),
axis.ticks = element_line(colour = "red"),
axis.line = element_line(colour = "blue")
)
Offset axis guide with minor ticks
Description
This guide draws the axis only as wide as the outermost tick marks, similar to offset axes from Prism. It also adds minor ticks.
Usage
guide_prism_offset_minor(
title = waiver(),
check.overlap = FALSE,
angle = NULL,
n.dodge = 1,
order = 0,
position = waiver()
)
Arguments
title |
A character string or expression indicating a title of guide.
If |
check.overlap |
silently remove overlapping labels, (recursively) prioritizing the first, last, and middle labels. |
angle |
Compared to setting the angle in
|
n.dodge |
The number of rows (for vertical axes) or columns (for horizontal axes) that should be used to render the labels. This is useful for displaying labels that would otherwise overlap. |
order |
A positive |
position |
Where this guide should be drawn: one of top, bottom, left, or right. |
Details
Control the length of the axis by adjusting the breaks
argument in
scale_(x|y)_continuous()
or scale_(x|y)_discrete()
. Similarly,
the number of minor ticks can be changed using the minor_breaks
argument.
Control the length of minor ticks by setting prism.ticks.length
to
a unit
object using theme
,
for example: prism.ticks.length = unit(2, "pt")
. The major tick
lengths are adjusted using the standard axis.ticks.length
.
Value
Returns a prism_offset_minor guide class object.
Examples
library(ggplot2)
## base plot
base <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
theme(axis.line = element_line(colour = "black"))
## add minor ticks to x and y axes
base +
scale_x_continuous(
limits = c(0, 6),
guide = "prism_offset_minor"
) +
scale_y_continuous(
limits = c(10, 35),
guide = "prism_offset_minor"
)
## you can also use the guides function to add minor ticks
base +
guides(x = "prism_offset_minor", y = "prism_offset_minor")
## adjust number of minor ticks by adjusting minor breaks
base +
scale_x_continuous(
limits = c(0, 6),
minor_breaks = seq(0, 6, 0.5),
guide = "prism_offset_minor"
) +
scale_y_continuous(
limits = c(10, 35),
minor_breaks = seq(10, 35, 1.25),
guide = "prism_offset_minor"
)
## adjust the length of major ticks with the usual axis.ticks.length element
base +
scale_x_continuous(
limits = c(0, 6),
minor_breaks = seq(0, 6, 0.5),
guide = "prism_offset_minor"
) +
scale_y_continuous(
limits = c(10, 35),
minor_breaks = seq(10, 35, 1.25),
guide = "prism_offset_minor"
) +
theme(
axis.ticks.length = unit(10, "pt")
)
## adjust the length of minor ticks with a new prism.ticks.length element
base +
scale_x_continuous(
limits = c(0, 6),
minor_breaks = seq(0, 6, 0.5),
guide = "prism_offset_minor"
) +
scale_y_continuous(
limits = c(10, 35),
minor_breaks = seq(10, 35, 1.25),
guide = "prism_offset_minor"
) +
theme(
axis.ticks.length = unit(10, "pt"),
prism.ticks.length = unit(5, "pt")
)
## to get log10 minor ticks just use a log10 scale and set the minor breaks
ggplot(msleep, aes(bodywt, brainwt)) +
geom_point(na.rm = TRUE) +
scale_x_log10(limits = c(1e0, 1e4),
minor_breaks = rep(1:9, 4)*(10^rep(0:3, each = 9)),
guide = "prism_offset_minor") +
theme(axis.line = element_line(colour = "black"))
## change colour and tick length with the usual elements
base +
scale_x_continuous(
limits = c(0, 6),
minor_breaks = seq(0, 6, 0.5),
guide = "prism_offset_minor"
) +
scale_y_continuous(
limits = c(10, 35),
minor_breaks = seq(10, 35, 1.25),
guide = "prism_offset_minor"
) +
theme(
axis.ticks.length = unit(10, "pt"),
prism.ticks.length = unit(5, "pt"),
axis.ticks = element_line(colour = "red"),
axis.line = element_line(colour = "blue")
)
Preview Prism themes
Description
Quickly generate a preview of a ggprism theme.
See names(ggprism_data$themes)
for valid palette names.
Usage
preview_theme(palette)
Arguments
palette |
|
Value
Returns an object of class ggplot.
Examples
library(ggplot2)
## see names of available themes
names(ggprism_data$themes)
## preview a theme
preview_theme("floral")
Prism colour palettes
Description
A collection of colour palettes which mirror the colour schemes available in GraphPad Prism.
Usage
prism_colour_pal(palette = "colors")
prism_color_pal(palette = "colors")
Arguments
palette |
|
Value
Returns a function which takes a single integer as its only argument and returns a character vector of hexadecimal colours. See the examples below for usage.
Examples
library(ggplot2)
## list all available colour palettes and their lengths
lengths(ggprism_data$colour_palettes)
## select some colours from a palette
prism_colour_pal(palette = "starry")(4)
## see all the colours in a specific palette
# define a function for convenience
library(scales)
show_palette <- function(palette) {
scales::show_col(
prism_colour_pal(palette = palette)(
attr(prism_colour_pal(palette = palette), "max_n")
)
)
}
# show the colours in the palette "pearl"
show_palette("pearl")
Prism fill palettes
Description
A collection of fill palettes which mirror the colour schemes available in GraphPad Prism.
Usage
prism_fill_pal(palette = "colors")
Arguments
palette |
|
Value
Returns a function which takes a single integer as its only argument and returns a character vector of hexadecimal colours. See the examples below for usage.
Examples
library(ggplot2)
## list all available fill palettes and their lengths
lengths(ggprism_data$fill_palettes)
## select some colours from a palette
prism_fill_pal(palette = "summer")(4)
## see all the colours in a specific palette
# define a function for convenience
library(scales)
show_palette <- function(palette) {
scales::show_col(
prism_fill_pal(palette = palette)(
attr(prism_fill_pal(palette = palette), "max_n")
)
)
}
# show the colours in the palette "pearl"
show_palette("floral")
Prism shape palettes
Description
Shape palettes that approximate those used in GraphPad Prism. No unicode characters are used, only the default symbols available in R.
Usage
prism_shape_pal(palette = c("default", "filled", "complete"))
Arguments
palette |
|
Details
The default
palette supports up to 9 values. It does not use
any symbols with a fill.
The filled
palette supports up to 10 values. The first 5 symbols
have a fill.
The complete
palette supports up to 14 values. Symbols 5 to 9
have a fill.
Value
Returns a function which takes a single integer as its only argument and returns a character vector of integers which correspond to R plot pch symbols. See the examples below for usage.
Examples
library(ggplot2)
## list all available shape palettes
ggprism_data$shape_palettes
## select some shapes from a palette
prism_shape_pal(palette = "filled")(4)
## see all the shapes in a specific palette
# define a function for convenience
show_shapes <- function(palette) {
df_shapes <- ggprism_data$shape_palettes[[palette]][, -1]
df_shapes$pch_f <- factor(df_shapes$pch, levels = df_shapes$pch)
ggplot(df_shapes, aes(x = 0, y = 0, shape = pch)) +
geom_point(aes(shape = pch), size = 5, fill = 'red') +
scale_shape_identity() +
facet_wrap(~ pch_f) +
theme_void()
}
# show the shapes in the palette "complete"
show_shapes("complete")
Prism colour scales (discrete)
Description
A collection of discrete colour scales that use palettes which mirror the colour schemes available in GraphPad Prism.
Usage
scale_colour_prism(palette = "colors", ...)
scale_color_prism(palette = "colors", ...)
Arguments
palette |
|
... |
Arguments passed on to
|
Value
Returns a ggproto object of class ScaleDiscrete which works with colour aesthetics.
Examples
library(ggplot2)
## base plot
base <- ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(cyl))) +
geom_point(size = 3)
## works pretty much the same as ggplot2 scale_colour_manual
base +
scale_colour_prism(palette = "candy_bright")
## try combining the ggprism colour and fill scales
base2 <- ggplot(mpg, aes(x = class, y = hwy, fill = class, colour = class)) +
geom_boxplot()
base2 +
scale_fill_prism(palette = "floral") +
scale_colour_prism(palette = "floral")
## change colour scale title in legend
base +
scale_colour_prism(
palette = "candy_bright",
name = "Cylinders"
)
## change colour labels in legend
base +
scale_colour_prism(
palette = "candy_bright",
name = "Cylinders",
label = c("4 cyl", "6 cyl", "8 cyl")
)
## change colour labels in legend with a function
base +
scale_colour_prism(
palette = "candy_bright",
name = "Cylinders",
label = function(x) paste(x, "cyl")
)
## change order of colours in legend
base +
scale_colour_prism(
palette = "candy_bright",
name = "Cylinders",
label = function(x) paste(x, "cyl"),
breaks = c(8, 4, 6)
)
## to change which colour is assigned to which cyl
## you need to change the factor levels in the underlying data
base <- ggplot(mtcars, aes(x = wt, y = mpg,
colour = factor(cyl, levels = c(6, 4, 8)))) +
geom_point(size = 3)
base +
scale_colour_prism(
palette = "candy_bright",
name = "Cylinders"
)
Prism fill scales (discrete)
Description
A collection of discrete fill scales that use palettes which mirror the colour schemes available in GraphPad Prism.
Usage
scale_fill_prism(palette = "colors", ...)
Arguments
palette |
|
... |
Arguments passed on to
|
Value
Returns a ggproto object of class ScaleDiscrete which works with fill aesthetics.
Examples
library(ggplot2)
## base plot
base <- ggplot(mtcars, aes(x = mpg, fill = factor(cyl))) +
geom_density(alpha = 0.75)
## works pretty much the same as ggplot2 scale_fill_manual
base +
scale_fill_prism(palette = "candy_bright")
## try combining the ggprism colour and fill scales
base2 <- ggplot(mtcars, aes(x = mpg, fill = factor(cyl), colour = factor(cyl))) +
geom_density(alpha = 0.75)
base2 +
scale_fill_prism(palette = "floral") +
scale_colour_prism(palette = "floral")
## change fill scale title in legend
base +
scale_fill_prism(
palette = "candy_bright",
name = "Cylinders"
)
## change fill labels in legend
base +
scale_fill_prism(
palette = "candy_bright",
name = "Cylinders",
label = c("4 cyl", "6 cyl", "8 cyl")
)
## change fill labels in legend with a function
base +
scale_fill_prism(
palette = "candy_bright",
name = "Cylinders",
label = function(x) paste(x, "cyl")
)
## change order of fills in legend
base +
scale_fill_prism(
palette = "candy_bright",
name = "Cylinders",
label = function(x) paste(x, "cyl"),
breaks = c(8, 4, 6)
)
## to change which fill is assigned to which cyl
## you need to change the factor levels in the underlying data
base <- ggplot(mtcars, aes(x = mpg,
fill = factor(cyl, levels = c(6, 4, 8)))) +
geom_density(alpha = 0.75)
base +
scale_fill_prism(
palette = "candy_bright",
name = "Cylinders"
)
Prism shape scales (discrete)
Description
Shape scales that approximate those used in GraphPad Prism. No unicode characters are used, only the default symbols available in R.
Usage
scale_shape_prism(palette = "default", ...)
Arguments
palette |
|
... |
Arguments passed on to
|
Details
The default
palette supports up to 9 values. It does not use
any symbols with a fill.
The filled
palette supports up to 10 values. The first 5 symbols
have a fill.
The complete
palette supports up to 14 values. Symbols 5 to 9
have a fill.
Value
Returns a ggproto object of class ScaleDiscrete which works with shape aesthetics.
Examples
library(ggplot2)
## list all available shape palettes
ggprism_data$shape_palettes
## define a base plot
base <- ggplot(mtcars, aes(x = wt, y = mpg,
shape = factor(cyl))) +
geom_point(size = 3)
## works pretty much the same as ggplot2 scale_shape_manual
base +
scale_shape_prism(palette = "complete")
## change shape scale title in legend
base +
scale_shape_prism(
palette = "default",
name = "Cylinders"
)
## change shape labels in legend
base +
scale_shape_prism(
palette = "default",
name = "Cylinders",
label = c("4 cyl", "6 cyl", "8 cyl")
)
## change shape labels in legend with a function
base +
scale_shape_prism(
palette = "default",
name = "Cylinders",
label = function(x) paste(x, "cyl")
)
## change order of shapes in legend
base +
scale_shape_prism(
palette = "default",
name = "Cylinders",
label = function(x) paste(x, "cyl"),
breaks = c(8, 4, 6)
)
## to change which shape is assigned to which cyl
## you need to change the factor levels in the underlying data
base <- ggplot(mtcars, aes(x = wt, y = mpg,
shape = factor(cyl, levels = c(6, 4, 8)))) +
geom_point(size = 3)
base +
scale_shape_prism(
palette = "default",
name = "Cylinders"
)
## see all the shapes in a specific palette
# define a function for convenience
show_shapes <- function(palette) {
df_shapes <- ggprism_data$shape_palettes[[palette]][, -1]
df_shapes$pch_f <- factor(df_shapes$pch, levels = df_shapes$pch)
ggplot(df_shapes, aes(x = 0, y = 0, shape = pch)) +
geom_point(aes(shape = pch), size = 5, fill = 'red') +
scale_shape_identity() +
facet_wrap(~ pch_f) +
theme_void()
}
# show the shapes in the palette "complete"
show_shapes("complete")
Prism themes
Description
A collection of ggplot2 themes that use palettes which mirror the colour schemes available in GraphPad Prism.
Usage
theme_prism(
palette = "black_and_white",
base_size = 14,
base_family = "sans",
base_fontface = "bold",
base_line_size = base_size/14,
base_rect_size = base_size/14,
axis_text_angle = 0,
border = FALSE
)
Arguments
palette |
|
base_size |
|
base_family |
|
base_fontface |
|
base_line_size |
|
base_rect_size |
|
axis_text_angle |
|
border |
|
Value
Returns a list-like object of class theme.
Examples
library(ggplot2)
# see ?preview_theme for a convenient function to preview ggprism themes
# before using theme_prism
## base plot
base <- ggplot(mpg, aes(x = displ, y = cty, colour = class)) +
geom_point()
## default palette is "black_and_white"
## default base_size is 14 (compared with 11 for theme_grey)
base +
theme_prism()
## try some other palettes
base +
theme_prism(palette = "office")
base +
theme_prism(palette = "flames")
## try matching the theme_prism palette with same colour palette
base +
theme_prism(palette = "stained_glass") +
scale_color_prism(palette = "stained_glass")
base +
theme_prism(palette = "candy_bright") +
scale_color_prism(palette = "candy_bright")
## change the font face
base +
theme_prism(base_fontface = "plain")
## change the font family
base +
theme_prism(base_family = "serif")
## base_line_size scales automatically as you change base_size
base +
theme_prism(base_size = 10)
## but you can also change it manually
base +
theme_prism(base_size = 16, base_line_size = 0.8)
## easily change x axis text angle
base +
theme_prism(axis_text_angle = 45)
## add a border (need to turn off clipping)
base +
theme_prism(border = TRUE) +
coord_cartesian(clip = "off")
## change border thickness
base +
theme_prism(border = TRUE, base_rect_size = 2) +
coord_cartesian(clip = "off")
Wing morphology of mutant flies
Description
Fold changes of different measures of wing morphology in heterozygous (Tps1MIC/+) and homozygous (Tps1MIC) Tps1 mutant flies. Data are expressed as percentage change relative to the mean of the heterozygous mutants.
Usage
wings
Format
An object of class tbl_df
(inherits from tbl
, data.frame
) with 120 rows and 4 columns.
Details
40 flies were measured in total, with 3 measurements taken per fly.
- sex
factor
. Male or female.- genotype
factor
. Heterozygous (Tps1MIC/+) or homozygous (Tps1MIC) mutant- measure
factor
. Type of wing measurement: wing size, cell size, or cell number- percent.change
double
. Value measured.
References
Matsushita, R, Nishimura, T. Trehalose metabolism confers developmental robustness and stability in Drosophila by regulating glucose homeostasis. Commun Biol 3, 170 (2020). doi:10.1038/s42003-020-0889-1