How can I plot the circle segment defined by three points with ggplot2?
I can only find the geom_curve function and that does define a segment by two points and the curvature argument.
Reproducible example:
df <- data.frame(
x = c(1,2,3),
y = c(2,2.5,1)
)
library(ggplot2)
p <- ggplot(data = df, aes(x = x, y = y)) + geom_point(col = "red") + xlim(0,4) + ylim(0,4)
p + geom_curve(aes(x = x[1], y = y[1], xend = x[3], yend = y[3]))
With changing the curvature argument I can come close to what I want:
p + geom_curve(aes(x = x[1], y = y[1], xend = x[3], yend = y[3]), curvature = -.8)
How can I calculate the curvature value given the three points (in order the segment really passes the middle point)?
Or even better: Are there alternative geom_ functions out there (in ggplot2 or an extension) that calculate segments by three points?
And the bonus question: Is there an alternative geom_ that really plots circle segments (since the geom_curve is not a circle segment but some fancy curve which can be seen best when setting curvature > 1)?
Edit after comment: ggforce::geom_bezier doesn't seem to do the trick. I tried:
library(ggforce)
df <- data.frame(
x = c(1,2,3),
y = c(2,2.5,1),
type = "quadratic",
point = c("end", "control", "end")
)
library(ggplot2)
p <- ggplot(data = df, aes(x = x, y = y)) + geom_point(col = "red") + xlim(0,4) + ylim(0,4)
p + geom_bezier(aes(x = x, y = y, group = type, linetype = type), data = df)






geom_beziershould do the trick, see my edit..