在R中为网格箭头指定gpar设置 [英] Specifying gpar settings for grid arrows in R
问题描述
我正在开发一个比例大小的箭头图,并且有一个大小,方向和箭头大小的工作流程,但箭头有两个问题:1.它们具有圆角连接和2。即使当 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 size),mm),type ='closed'))+
scale_size(range = c(2,4))
箭头基于,并且做出以下改动,你将以可爱的尖头箭头结束:
1 require(proto)
2添加 ggplot :::
在GeomSegment的第一行(当前是第51行),如下所示:
GeomSegment < - proto(ggplot ::: Geom,{
<3>在
segmentsGrob
中添加参数 linejoin ='miter'
至 gpar
(第23行): 运行这两个函数,您将得到: I'm developing a plot of proportionally sized arrows, and have a workflow for size, direction and arrow-head size, but there are a couple of issues with the arrowheads: 1. they have rounded line-join and 2. they don't close (see bottom right corner) even when Arrows are based on grid graphics, but I cannot figure out how to specify the setting. but Edit Plot image including grid.segments arrow added: Found a solution (credit to @baptiste for the pointer). If you use the geom_segment source code in github and make the following alterations you will end up with lovely pointy arrowheads: 1 2 add 3 add argument Run both functions and you'll end up with: 这篇关于在R中为网格箭头指定gpar设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! lwd = size * .pt,lty = linetype,lineend = lineend,linejoin ='miter'),
$ b $ p
$ b
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))
get.gpar()
yields:$lineend
[1] "round"
$linejoin
[1] "round"
gpar(linejoin = 'mitre', lineend = 'butt')
does not change this. Is there any way to change these settings? Thanks in advance.
require(proto)
ggplot:::
in first line of GeomSegment (currently line 51) as follows:GeomSegment <- proto(ggplot:::Geom, {
linejoin = 'mitre'
to gpar
in segmentsGrob
(line 23):lwd=size * .pt, lty=linetype, lineend = lineend, linejoin = 'mitre'),