I am setting up a plotting space for a scatterplot and I am trying to add axes with arrowed tips using the geom_segment function in ggplot2.
This is the code I have so far:
Max <- 5;
xaxis1 <- c(-Max,0);
xaxis2 <- c(Max,0);
yaxis1 <- c(0,-Max);
yaxis2 <- c(0,Max);
ggplot() +
coord_cartesian(xlim = c(-Max,Max), ylim = c(-Max,Max)) +
theme_minimal() +
scale_y_continuous(expand = c(0,0)) +
scale_x_continuous(expand = c(0,0)) +
geom_segment(aes(x = xaxis1, y = yaxis1, xend = xaxis2, yend = yaxis2),
color = "black",
linewidth = 1,
lineend = "round",
linejoin = "round",
arrow = arrow(length = unit(0.4, "cm"), ends = "both"))
As you can hopefully see from the below image, the arrow tips on the horizontal axis are shifted down slightly and the arrow tips on the vertical axis are shifted right slightly. How can I make the plot so that they are perfectly centered on the line?