【问题标题】:Add curly brackets for axis area in a plot [closed]在图中为轴区域添加大括号[关闭]
【发布时间】:2014-05-26 11:53:32
【问题描述】:

我想在绘图中的轴旁边添加大括号。花括号应如下所示:

【问题讨论】:

  • 你试过mtext 吗?
  • 基本图形(可以假设带有plot 标签,购买不清楚)? ggplot2 图形?你试过什么了?样本数据/图?
  • 感谢迄今为止的投入。它只是一个正常的情节。在这里你可以看到一个例子:r-forum.de/resources/image/40
  • 欢迎来到 StackOverflow!请阅读有关how to ask a question 的信息以及如何生成minimal reproducible example。还分享您迄今为止尝试过的任何代码。这将使其他人更容易帮助您。
  • This post 和 this 一个显示了一些选项。否则,?arrows 是另一种选择。

标签: r plot


【解决方案1】:

感谢this 的回答,我只是做了一些乱七八糟的调整。添加xpd=NA 可以让您在情节之外进行绘制:

# function to draw curly braces
# x, y position where to put the braces
# range is the length of the brace
# position: 1 vertical, 2 horizontal
# direction: 1 left/down, 2 right/up
# depth controls width of the shape

CurlyBraces <- function(x0, x1, y0, y1, pos = 1, direction = 1, depth = 1) {

    a=c(1,2,3,48,50)    # set flexion point for spline
    b=c(0,.2,.28,.7,.8) # set depth for spline flexion point

    curve = spline(a, b, n = 50, method = "natural")$y * depth

    curve = c(curve,rev(curve))

    if (pos == 1){
        a_sequence = seq(x0,x1,length=100)
        b_sequence = seq(y0,y1,length=100)  
    }
    if (pos == 2){
        b_sequence = seq(x0,x1,length=100)
        a_sequence = seq(y0,y1,length=100)      
    }

    # direction
    if(direction==1)
        a_sequence = a_sequence+curve
    if(direction==2)
        a_sequence = a_sequence-curve

    # pos
    if(pos==1)
        lines(a_sequence,b_sequence, lwd=1.5,   xpd=NA) # vertical
    if(pos==2)
        lines(b_sequence,a_sequence, lwd=1.5, xpd=NA) # horizontal

}

windows(width=5, height=5)
par(oma=c(2,0,0,2))
plot(c(),c(), xlim=c(0,11), ylim=c(0,11), xlab='')
# horizontal brace
CurlyBraces(x0=2,  x1=8,  y0=-3, y1=-3, pos = 2, direction = 2, depth=1.5)
# vertical brace
CurlyBraces(x0=12, x1=12, y0=2, y1=6, pos = 1, direction = 1, depth=0.5)

【讨论】:

  • 非常感谢。太好了!!
猜你喜欢
  • 1970-01-01
  • 2021-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-13
  • 2010-11-04
相关资源
最近更新 更多