inset_element ¶
inset_element(
plot: PlotSpec | SupPlotsSpec,
left: float,
bottom: float,
right: float,
top: float,
align_to: Literal["panel", "plot", "full"] = "panel",
on_top: bool = True,
clip: bool = True,
ignore_tag: bool = False,
) -> InsetSpec
Draw a plot (or grid) inside the area of the plot it is added to.
A ggrust extension (patchwork inset_element()); add it with +:
main + inset_element(detail, 0.6, 0.6, 1, 1). Later + still changes
main. Insets of grid plots are numbered by gggrid(tag_levels=) after
their host.
Parameters:
-
plot(PlotSpec or SupPlotsSpec) –The inset figure.
-
left(float) –Edges as fractions (0..1) of the area
align_tonames: 0 is its left or bottom edge, 1 its right or top edge. -
bottom(float) –Edges as fractions (0..1) of the area
align_tonames: 0 is its left or bottom edge, 1 its right or top edge. -
right(float) –Edges as fractions (0..1) of the area
align_tonames: 0 is its left or bottom edge, 1 its right or top edge. -
top(float) –Edges as fractions (0..1) of the area
align_tonames: 0 is its left or bottom edge, 1 its right or top edge. -
align_to((panel, plot, full), default:"panel") –The area: the panels, the plot without its titles, caption, legends, tag and margin (panels, axes and axis titles), or the whole figure.
-
on_top(bool, default:True) –Draw over the host, or under it (above its background).
-
clip(bool, default:True) –Cut the inset at its area.
-
ignore_tag(bool, default:False) –Leave the inset out of
gggrid(tag_levels=)numbering.
Returns:
-
InsetSpec–The inset, to add to a plot or grid with
+.
Raises:
-
TypeError–If
plotis not a plot or grid, or a flag is not a bool. -
SpecError–If an edge is outside 0..1, the inset is empty (
left >= rightorbottom >= top), oralign_tois unknown.
Examples:
>>> from ggrust import *
>>> data = {"weight": [2.6, 2.9, 3.2, 3.4, 3.6, 4.1], "mpg": [31, 28, 24, 22, 19, 15]}
>>> main = ggplot(data, aes("weight", "mpg")) + geom_point()
>>> detail = ggplot(data, aes("mpg")) + geom_histogram(bins=4)
>>> plot = main + inset_element(detail, 0.55, 0.55, 1, 1)