I'm trying to extract xy coordinates for points along a curved line in a ggplot. ggplot_build()
shows some of the data, but it still only contains the start and end coordinates of the curve. Is there any way to get at the intermediate points?
Edit: Example code using geom_curve()
.
ggplot(df, aes(x = x, y = y, xend = xend, yend=yend)) + geom_curve(curvature = .4)
Here's my best attempt, given the info you've supplied. If you could provide a reproducible example, perhaps a better solution could be supplied.
p <- ggplot(mpg, aes(cty, hwy)) +
geom_smooth()
x_coords <- ggplot_build(p)$data[[1]]$x
y_coords <- ggplot_build(p)$data[[1]]$y
p
plot(x_coords, y_coords, type = "l")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.