geom_marquee | R Documentation |
The geom is an extension of geom_text()
and geom_label()
that allows you
to draw richly formatted text in marquee-markdown format in your plot. For
plain text it is a near-drop-in replacement for the above geoms except some
sizing might be very slightly different. However, using this geom you are
able to access the much more powerful font settings available in marquee, so
even then it might make sense to opt for this geom.
geom_marquee(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
size.unit = "mm",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer.
Cannot be jointy specified with
|
... |
Other arguments passed on to
|
size.unit |
How the |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
Styling of the text is based on a style set with the exception that the
standard aesthetics such as family, size, colour, fill, etc. are recognized
and applied to the base tag style. The default style set (classic_style)
can be changed using the style aesthetic which can take a vector of style
sets so that each text can rely on it's own style if needed. As with
element_marquee()
, the fill
aesthetic is treated differently and not
applied to the base tag, but to the body tag as a skip_inherit()
style so
as to not propagate the fill.
Contrary to the standard text and label geoms, geom_marquee()
takes a
width
aesthetic that can be used to turn on soft wrapping of text. The
default value (NA
) lets the text run as long as it want's (honoring hard
breaks), but setting this to something else will instruct marquee to use at
most that amount of space. You can use grid units to set it to an absolute
amount.
A ggplot2 layer that can be added to a plot
library(ggplot2)
# Standard use
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_marquee(aes(label = rownames(mtcars)))
# Make use of more powerful font features (note, result may depend on fonts
# installed on the system)
p + geom_marquee(
aes(label = rownames(mtcars)),
style = classic_style(weight = "thin", width = "condensed")
)
# Turn on line wrapping
p + geom_marquee(aes(label = rownames(mtcars)), width = unit(2, "cm"))
# Style like label
label_style <- modify_style(
classic_style(),
"body",
padding = skip_inherit(trbl(4)),
border = "black",
border_size = skip_inherit(trbl(1)),
border_radius = 3
)
p + geom_marquee(aes(label = rownames(mtcars), fill = gear), style = label_style)
# Use markdown to style the text
red_bold_names <- sub("(\\w+)", "{.red **\\1**}", rownames(mtcars))
p + geom_marquee(aes(label = red_bold_names))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.