I am trying to label a straight line segment using annotate
. However, setting the angle of the annotation to the slope of the line does not align the annotation to the line segment.
library(ggplot2)
ggplot(data.frame(x = seq(0, 14, 0.1)), aes(x = x)) +
stat_function(fun = function(x) {
14 - x
}, geom = "line") +
theme_bw() +
annotate(
geom = "text",
x = 7.5, y = 7.5,
label = "x + y = 14",
angle = -45) # NISTunits::NISTradianTOdeg(atan(-1))
This gives:
Can someone help explain this phenomenon, and how to fix this, i.e., align the annotation to have the same angle as the line segment?