How to add braces to a graph?

后端 未结 5 760
北荒
北荒 2020-12-01 12:23

I want to make the following graph in R:

\"enter

How can I plot those horizont

5条回答
  •  臣服心动
    2020-12-01 13:16

    A little Googling turn up some grid code from a thread on the R help mailing list here. At the very least it gives you something to work with. Here's the code from that post:

    library(grid)
    
    # function to draw curly braces in red
    # x1...y2 are the ends of the brace
    # for upside down braces, x1 > x2 and y1 > y2
    Brack <- function(x1,y1,x2,y2,h)
    {
       x2 <- x2-x1; y2 <- y2-y1
       v1 <- viewport(x=x1,y=y1,width=sqrt(x2^2+y2^2),
               height=h,angle=180*atan2(y2,x2)/pi,
               just=c("left","bottom"),gp=gpar(col="red"))
       pushViewport(v1)
       grid.curve(x2=0,y2=0,x1=.125,y1=.5,curvature=.5)
       grid.move.to(.125,.5)
       grid.line.to(.375,.5)
       grid.curve(x1=.375,y1=.5,x2=.5,y2=1,curvature=.5)
       grid.curve(x2=1,y2=0,x1=.875,y1=.5,curvature=-.5)
       grid.move.to(.875,.5)
       grid.line.to(.625,.5)
       grid.curve(x2=.625,y2=.5,x1=.5,y1=1,curvature=.5)
       popViewport()}
    

提交回复
热议问题