R:为图中的轴区域添加大括号

标签 r plot

关闭。这个问题需要details or clarity .它目前不接受答案。












想改善这个问题吗?通过 editing this post 添加详细信息并澄清问题.

7年前关闭。




Improve this question




我想在 R 图中的轴旁边添加大括号。大括号应该是这样的:

enter image description here

最佳答案

所有功劳都归于 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)

enter image description here

关于R:为图中的轴区域添加大括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31708454/

相关文章:

python - 尝试绘制简单的条形图时出错

r - 如何在 R 中使用相同的种子在并行或不并行的情况下产生相同的输出?

python - 更改 Matplotlib 字体而不影响全局

oop - 有没有办法为 S4 引用类声明公共(public)和私有(private)方法?

r - Shiny 的应用程序与服务器断开连接。没有错误

python - matplotlib中从右到左的水平条形图

python - 用 Python 绘制 Highcharts 图

python - 如何用字符串作为 x 轴值绘制两个图

r - 包函数中的 stop() 不会结束 Debug模式

r - 将 nls 拟合到分组数据 R