ggplot2 - 如何在ggplot2中的线段之间绘制角弧?
问题描述
是否可以使用 ggplot2(或 plotnine 或其他图形包语法)在两条直线段之间绘制角弧,如下所示?
(忽略圆圈等)
我知道这可以通过 Geogebra 等图形程序来完成。但我有兴趣在 Jupyter 中以编程方式绘制角度标记(和标签)。
(对了,这个“角弧”有没有一个词?我不知道怎么称呼,就用了“角弧”。)
解决方案
对于 R,有ggforce
一个扩展 ggplot2 并定义了一个geom_arc()
非常接近的包。下面的例子:
library(ggplot2)
library(ggforce)
start <- c(x = 0, y = 0)
dat <- data.frame(
x = start[c("x", "x")],
y = start[c("y", "y")],
xend = c(1, 4),
yend = c(5, 1)
)
angles <- with(dat, atan2(xend - x, yend - y))
ggplot(dat) +
geom_segment(aes(x, y, xend = xend, yend = yend)) +
geom_arc(aes(x0 = start["x"], y0 = start["y"], r = 1,
start = angles[1], end = angles[2])) +
coord_equal()
推荐阅读
- java - 从文件夹spring boot加载文件
- python-3.x - 在 Webdriver 的不同实例中维护 Session
- python - 字典中的唯一组合值
- rest - 一对一资源的 REST 端点应该是什么?
- html - 引导标签和输入字段对齐问题
- javascript - 将连接帐户的 Stripe 费用 ID 和帐户 ID 公开给客户端是否安全?
- python-3.x - selenium python fullscreen_window
- java - 实际参数和格式参数的长度不同
- python - 在 Tensorflow 中删除张量的维度
- php - 页面标题显示“导航栏”而不是页面标题