library(ggplot2)
library(magrittr)
library(tidyr)
# Generate some dummy data
ten.points <- data.frame(line.no = rep(1:5, each = 2), x = runif(10), y = runif(10),
position = rep(c("start", "end"), 5))
five.segments <- ten.points %>% pivot_wider(names_from = position, values_from = c(x,y))
# Default behaviour
ggplot(five.segments) +
geom_point(data = ten.points, aes(x = x, y = y)) +
geom_arrowsegment(aes(x = x_start, xend = x_end, y = y_start, yend = y_end))
# Midpoint arrowheads
ggplot(five.segments) +
geom_point(data = ten.points, aes(x = x, y = y)) +
geom_arrowsegment(aes(x = x_start, xend = x_end, y = y_start, yend = y_end),
arrow_positions = 0.5)
# Double arrows
ggplot(five.segments) +
geom_point(data = ten.points, aes(x = x, y = y)) +
geom_arrowsegment(aes(x = x_start, xend = x_end, y = y_start, yend = y_end),
arrow_positions = c(0.25, 0.75))
# Double arrows, last arrowhead at the end point
ggplot(five.segments) +
geom_point(data = ten.points, aes(x = x, y = y)) +
geom_arrowsegment(aes(x = x_start, xend = x_end, y = y_start, yend = y_end),
arrow_positions = c(0.25, 1))
# Double arrowheads of varying appearance and position
ggplot(five.segments) +
geom_point(data = ten.points, aes(x = x, y = y)) +
geom_arrowsegment(aes(x = x_start, xend = x_end, y = y_start, yend = y_end),
arrow_positions = c(0.25, 0.75),
arrows = list(arrow(angle = 45, type = "closed"),
arrow(angle = 25, ends = "both")),
arrow_fills = "indianred")
Run the code above in your browser using DataLab