ggplot2 geom_curve() in R: Draw Curved Connections
The geom_curve() function in ggplot2 draws CURVED arcs between two points, useful for connecting nodes in network plots, decorative annotations, or stylistic alternatives to straight segments.
ggplot(df, aes(x, y, xend = xend, yend = yend)) + geom_curve() geom_curve(curvature = 0.5) # curvier geom_curve(curvature = -0.5) # bend other direction geom_curve(angle = 45) # control arc orientation geom_segment() # straight version
Need explanation? Read on for examples and pitfalls.
What geom_curve() does in one sentence
geom_curve() draws curved (arc) line segments from (x, y) to (xend, yend) for each row of data. Same arguments as geom_segment plus curvature and angle.
Syntax
geom_curve(mapping = NULL, data = NULL, curvature = 0.5, angle = 90, ncp = 5, arrow = NULL, ...). Requires aes(x, y, xend, yend).
Five common patterns
1. Standard curve
2. Reverse direction
3. Tight curve
4. Curve with arrow
5. Network edges
curvature controls bend AMOUNT; angle controls bend DIRECTION. Most users only need curvature; angle is for fine-tuning.geom_curve() vs geom_segment() vs geom_line()
| Function | Shape | Endpoints |
|---|---|---|
geom_curve() |
Curved arc | (x, y) to (xend, yend) per row |
geom_segment() |
Straight | (x, y) to (xend, yend) per row |
geom_line() |
Polyline | Across rows in sorted x |
A practical workflow
Use geom_curve for stylistic annotations or network edge plots.
Common pitfalls
Pitfall 1: too much curvature. Above 1 produces extreme bends. Stay 0 to 1 for natural-looking arcs.
Pitfall 2: missing aesthetics. Like geom_segment, requires x, y, xend, yend.
geom_curve() doesn't connect across rows. Each row is one curve. For curved trajectories across many points, use geom_path with smoothing.Try it yourself
Try it: Draw a curved arrow from (0,0) to (5,5). Save to ex_plot.
Click to reveal solution
Explanation: Curve with curvature 0.3 and arrow at the end.
Related ggplot2 functions
After mastering geom_curve, look at:
geom_segment(): straight versionarrow(): arrowhead specgeom_path()/geom_line(): multi-point linesannotate(): one-off annotations
FAQ
What does geom_curve do in ggplot2?
geom_curve() draws curved arc segments between (x, y) and (xend, yend). Same as geom_segment but curved.
How do I control the curve direction?
Use the curvature argument: positive curves clockwise; negative counterclockwise; 0 is straight.
What is the difference between geom_curve and geom_segment?
geom_segment is straight; geom_curve is curved. Otherwise identical aesthetics and arguments.
Can I add an arrow to geom_curve?
Yes. Pass arrow = arrow(). Same as geom_segment.
Does curvature have to be between 0 and 1?
No, but values outside this range produce extreme curves. Practical range is 0 to 1.