View source: R/element-text-repel.R
| element_text_repel | R Documentation |
This text element is a replacement for element_text
that repulses labels.
element_text_repel(
family = NULL,
face = NULL,
colour = NULL,
size = NULL,
hjust = NULL,
vjust = NULL,
angle = NULL,
lineheight = NULL,
color = NULL,
margin = NULL,
box.padding = NULL,
force = NULL,
force_pull = NULL,
max.time = NULL,
max.iter = NULL,
max.overlaps = NULL,
min.segment.length = NULL,
segment.colour = NULL,
segment.linetype = NULL,
segment.size = NULL,
segment.curvature = NULL,
segment.angle = NULL,
segment.ncp = NULL,
segment.shape = NULL,
segment.square = NULL,
segment.squareShape = NULL,
segment.inflect = NULL,
arrow = NULL,
seed = NA,
position = c("bottom", "top", "left", "right"),
inherit.blank = FALSE
)
family |
The typeface to use. The validity of this value will depend on
the graphics device being used for rendering the plot. See
the systemfonts vignette
for guidance on the best way to access fonts installed on your computer.
The values |
face |
Font face ("plain", "italic", "bold", "bold.italic") |
colour, color |
Line/border colour. Color is an alias for colour.
|
size |
Font size in points. |
hjust |
Horizontal justification (in |
vjust |
Vertical justification (in |
angle |
Angle (in |
lineheight |
Line height |
margin |
Margins around the text. See |
box.padding |
Amount of padding around bounding box, as unit or number.
Defaults to 0.25. (Default unit is lines, but other units can be specified
by passing |
force |
Force of repulsion between overlapping text labels. Defaults to 1. |
force_pull |
Force of attraction between a text label and its corresponding data point. Defaults to 1. |
max.time |
Maximum number of seconds to try to resolve overlaps. Defaults to 0.5. |
max.iter |
Maximum number of iterations to try to resolve overlaps. Defaults to 10000. |
max.overlaps |
Exclude text labels when they overlap too many other things. For each text label, we count how many other text labels or other data points it overlaps, and exclude the text label if it has too many overlaps. Defaults to 10. |
min.segment.length |
Skip drawing segments shorter than this, as unit or
number. Defaults to 0.5. (Default unit is lines, but other units can be
specified by passing |
segment.colour, segment.linetype, segment.size |
Graphical parameters for the line connecting the text to points of origin. |
segment.curvature, segment.angle, segment.ncp, segment.shape, segment.square, segment.squareShape, segment.inflect |
Settings for curving the connecting line. See |
arrow |
Arrow specification, as created by |
seed |
Random seed passed to |
position |
One of |
inherit.blank |
Should this element inherit the existence of an
|
An object of class <element_text_repel>.
# A plot with a crowded y-axis
p <- ggplot(mtcars, aes(mpg, rownames(mtcars))) +
geom_col() +
coord_cartesian(ylim = c(-32, 64)) +
theme(axis.text.y = element_text_repel())
# By default there isn't enough space to draw distinctive lines
p
# The available space can be increased by setting the margin
p + theme(axis.text.y.left = element_text_repel(margin = margin(r = 20)))
# For secondary axis positions at the top and right, the `position` argument
# should be set accordingly
p + scale_y_discrete(position = "right") +
theme(axis.text.y.right = element_text_repel(
margin = margin(l = 20),
position = "right"
))
# Using segment settings and matching tick colour
p + theme(
axis.text.y.left = element_text_repel(
margin = margin(r = 20),
segment.curvature = -0.1,
segment.inflect = TRUE,
segment.colour = "red"
),
axis.ticks.y.left = element_line(colour = "red")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.