Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用R创建用于显示案例计数的树状图_R_Data Visualization - Fatal编程技术网

使用R创建用于显示案例计数的树状图

使用R创建用于显示案例计数的树状图,r,data-visualization,R,Data Visualization,我需要创建一个类似“树状图”的图表来表示不同场景的案例数量,如下所示: 图片引自: Pediatrics. 2005 Dec;116(6):1317-22. Electronic surveillance system for monitoring surgical antimicrobial prophylaxis. Voit SB, Todd JK, Nelson B, Nyquist AC. 我可以使用table命令从R中轻松获得数字,但这不是一种很好的表示方法 图表可以不使用任何花哨

我需要创建一个类似“树状图”的图表来表示不同场景的案例数量,如下所示:

图片引自:

Pediatrics. 2005 Dec;116(6):1317-22.
Electronic surveillance system for monitoring surgical antimicrobial prophylaxis.
Voit SB, Todd JK, Nelson B, Nyquist AC.
我可以使用
table
命令从R中轻松获得数字,但这不是一种很好的表示方法


图表可以不使用任何花哨的颜色或东西制作,我只想用这种格式来表示数字。有什么建议吗?

可以使用“图表”包绘制树形图。它是绘制流程图等的通用软件包。请参阅


library(diagram)
demo("flowchart")

我每周都会收到类似的要求,要求制作这些类型的图表。我做了skullkey建议的,然后我做了这个。它可能没有你展示的那么好,但它有主旨

consort.dia <- function(
screened=45,
eligible=46,
neligible=47,
interested=48,
ninterested=49,
consented=50,
nconsented=51,
treat=52,
control=53
){
require(diagram)

 openplotmat(main="Consort Diagram")

 elpos<-coordinates (c(1,3,3,4,5))

 fromto <- matrix(ncol=2,byrow=TRUE,
                 data=c(1,2,
                        1,3,
                        1,4,
                        2,5,
                        2,6,
                        2,7,
                        5,8,
                        5,9,
                        5,10,
                        8,12,
                        8,13
                      )
            )

 nr     <-nrow(fromto)

 arrpos <- matrix(ncol=2,nrow=nr)

 for (i in 1:nr) 
     arrpos[i,] <- straightarrow (  
                        to=elpos[fromto[i,2],],
                        from=elpos[fromto[i,1],],
                        lwd=2,arr.pos=0.6,
                        arr.length=0.5
                       )

 textrect   (elpos[1,],radx=.094,rady=.05,lab=paste("Screened\n",screened))

 textrect   (elpos[2,],radx=.094,rady=.05,lab=paste("Eligible\n",eligible))

 textrect   (elpos[3,],radx=.094,rady=.05,lab=paste("Not Eligible\n",neligible))

 textrect   (elpos[4,],radx=.094,rady=.05,lab=paste("Screening \n Incomplete\n",screened-(neligible+eligible)))

 textrect   (elpos[5,],radx=.094,rady=.05,lab=paste("Interested\n",interested))

 textrect   (elpos[6,],radx=.094,rady=.05,lab=paste("Not Interested\n",ninterested))

 textrect   (elpos[8,],radx=.094,rady=.05,lab=paste("Consented\n",consented))

 textrect   (elpos[9,],radx=.094,rady=.05,lab=paste("Not Consented\n",nconsented))

 textrect   (elpos[12,],radx=.094,rady=.05,lab=paste("Treatment\n",treat))

 textrect   (elpos[13,],radx=.094,rady=.05,lab=paste("Control\n",control))

 textrect   (elpos[7,],radx=.094,rady=.05,lab=paste("Unable to \nReach\n",eligible-{interested+ninterested}))

 textrect   (elpos[10,],radx=.094,rady=.05,lab=paste("In Progress\n",interested-{consented+nconsented}))

}
consort.dia
库(图)
par(mfrow=c(1,1))
par(mar=c(0,0,0,0))
##初始化新的图形设备
openplotmat()
##每行的元素数

ELPOSIR将天真地推荐VIGET看起来有你要找的东西。你也可以考虑<代码> PLOTIX::Trime.DruttS/<代码>,如果每个类别有很多级别,那就有用了。有一个工具可以从父子数据自动生成树形图(层次结构)。输入是文本文件,其中每行重新显示一个节点。在每个节点中都有节点ID、节点名称、父ID?@Dantes如果你想问一个相关的问题,你应该开始一个新的问题,并添加一个链接到here@lokheart我很乐意这么做,但是这个Stackoverflow团队已经为我禁用了这个选项。。。他们说我的问题是无效的?!?!感谢Skullkey,我使用这个包创建了一个投掷n枚硬币的图表——是否有一个工具可以从父子数据自动生成树形图(层次结构)。输入是文本文件,其中每行重新显示一个节点。每个节点中都有节点ID、节点名称、父ID?
library(diagram)
par(mfrow=c(1,1))
par(mar=c(0,0,0,0))
##initialize new grphics device
openplotmat()
##number of elements per row
elpos<-coordinates (c(1,1, 2, 2, 2, 3,2 ))
##draw arrows from each row to next row
treearrow(from=elpos[1,],to=elpos[2,],lwd=6)  
treearrow(from=elpos[2,],to=elpos[3:4,],lwd=6) 
treearrow(from=elpos[3,],to=elpos[5,],lwd=6)  
treearrow(from=elpos[4,],to=elpos[6,],lwd=6)  

treearrow(from=elpos[5,],to=elpos[7:8,],lwd=6)  

treearrow(from=elpos[7,],to=elpos[9:10,],lwd=6)
treearrow(from=elpos[8,],to=elpos[11,],lwd=6)  

treearrow(from=elpos[9,],to=elpos[12,],lwd=6)  
treearrow(from=elpos[10,],to=elpos[13,],lwd=6)

##create a generic 3-lined label for each textbox
labels = vector(length=13)
for(i in 1:13) { 
labels[i] = paste(c(sample(letters, 3), "\n", sample(letters, 3) , "\n", sample(letters, 3)), collapse="")
}
labels[12] = "Consistent with AAP\nguidelines"

##plot text boxes
for ( i in 1:13) textround (elpos[i,],radx=0.08,rady=0.05,lab=labels[i])