View source: R/geom_segment_plus.R
| geom_segment_plus | R Documentation |
Still a WIP. The dropping and warning of segments switching directions isn't really working correctly yet. geom_segment_plus is an updated version of mo-seph's Stack Overflow code (https://stackoverflow.com/q/14647988/4560765), which no longer works. mo-seph's code in turn is an extension of ggplot2's geom_segment, but with the ability to offset segments that overlap, and to shorten the end or beginning of the segment.
geom_segment_plus(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
arrow = NULL,
arrow.fill = NULL,
lineend = "butt",
linejoin = "round",
shorten.limit = c("warn", "drop", "ignore"),
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
mapping, data, ..., stat, parse, inherit.aes |
See the documentation for |
This code basically has three new possible parameters:
shorten.start/shorten.end: this moves the start/end of the segment closer to the midpoint by a proportion
shorten.start.abs/shorten.end.abs: this moves the start/end of the segment closer to the midpoint by an absolute value
offset: if two segments fully overlap, this offsets them slightly
d <- data.frame(x=c(-1,1),
y=c(-1,1),
x.to=c(2,-1),
y.to=c(-1,1))
d %>%
ggplot(aes( x=x, y=y ) ) +
geom_point() +
geom_segment_plus(aes( x=x, y=y, xend=x.to, yend=y.to ),
lineend="round", arrow=arrow(length=unit(0.15, "inches")),
offset=0.00, shorten.start=0.5, shorten.end=0,
shorten.end.abs=0.15,
shorten.limit = 'drop')
d %>%
ggplot(aes( x=x, y=y ) ) +
geom_point() +
geom_segment_plus(aes( x=x, y=y, xend=x.to, yend=y.to ),
lineend="round", arrow=arrow(length=unit(0.15, "inches")),
offset=0.00, shorten.start=1, shorten.end=0,
shorten.end.abs=1.25,
shorten.limit = 'drop')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.