如何添加大括号到图形? [英] How to add braces to a graph?

查看:162
本文介绍了如何添加大括号到图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在R中制作下面的图表:



如何绘制水平大括号?

解决方案

一些Google搜索从R帮助邮件列表中的一个主题调出一些网格代码这里。至少它会给你一些工作。以下是该帖子的代码:

  library(grid)

#函数用于绘制花括号红色
#x1 ... y2是大括号的结尾
#用于颠倒大括号,x1> x2和y1> y2
Brack < - 函数(x1,y1,x2,y2,h)
{
x2 < - x2-x1; y2 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。 (.375,.5)
grid.curve(x1 = .375,y1 = .5,x2 = .5,y2 = 1,curvature = .5)
grid.curve(x2 = 1,y2 = 0,x1 = .875,y1 = .5,曲率= - 。5)
grid.move.to(.875,.5)
grid.line.to(.625 ,.5)
grid.curve(x2 = .625,y2 = .5,x1 = .5,y1 = 1,curvature = .5)
popViewport()}


I want to make the following graph in R:

How can I plot those horizontal braces?

解决方案

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()}

这篇关于如何添加大括号到图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆