我正在开发一个比例大小的箭头图,并且有一个尺寸,方向和箭头尺寸的工作流程,但箭头有几个问题:1.它们有圆形连线和2.它们不是' t关闭(见右下角)即使type='closed'.
require(ggplot2)
require(grid)
d = data.frame(x = 1:10, y = 0, size = 1:10)
ggplot(d, aes(x, y, size = size)) +
geom_segment(aes(xend = x, yend = y + size),
arrow = arrow(length = unit(d$size, "mm"), type='closed')) +
scale_size(range = c(2, 4))
Run Code Online (Sandbox Code Playgroud)

箭头基于网格图形,但我无法弄清楚如何指定设置. get.gpar()收益率:
$lineend
[1] "round"
$linejoin
[1] "round"
Run Code Online (Sandbox Code Playgroud)
但gpar(linejoin = 'mitre', lineend = 'butt')不会改变这一点.有没有办法改变这些设置?提前致谢.
编辑
绘制的图片包括grid.segments箭头添加:

找到了一个解决方案(归功于@baptiste 的指针)。如果您使用github 中的geom_segment 源代码并进行以下更改,您最终会得到可爱的尖箭头:
1require(proto)
2ggplot:::在GeomSegment的第一行(当前为第51行)添加如下:
GeomSegment <- proto(ggplot:::Geom, {
3 添加参数linejoin = 'mitre'到gparin segmentsGrob(第 23 行):
lwd=size * .pt, lty=linetype, lineend = lineend, linejoin = 'mitre'),
运行这两个函数,你最终会得到:

| 归档时间: |
|
| 查看次数: |
1905 次 |
| 最近记录: |