English 中文(简体)
如何在树苗的终点站添加标签?
原标题:How to add labels to the terminal nodes of a ctree (package party)?

我用树树种建立了双平级树。 我希望每个终点站都包含与这一节点相关的行名。 我如何能够做到这一点?

例如,关于以下数据集,我希望最左的节点分别列出所有年龄和生育年龄的人、23(Abner to Abudemio)和最合适的Abundiantus到Acelin。

      names       age height young   
1     Abner       18   76.1   yes
2     Abraham     19   77.0   yes
3     Abram       20   78.1   yes
4     Abrasha     21   78.2   yes
5     Absalom     22   78.8   yes
6     Abudemio    23   79.7   yes
7     Abundiantus 24   79.9    no
8     Acacio      25   81.1    no
9     Acario      26   81.2    no
10    Accursius   27   81.8    no
11    Ace         28   82.8    no
12    Acelin      29   83.5    no

“entergraph

最佳回答

这里是一个 ha的解决办法。 它对从<条码>缔约方一揽子计划中设定功能的原始源代码几乎没有改动。 通过阅读源代码,我注意到,如果结果是个因素,则有<条码>,即“终端_panel,即:<条码>_barplot<>。 (如果安装了源包,则每一条都在<代码>R/plot.R功能中。) 以后,我们可以修改,在缺货一览表中显示海关标签。

Just issue the following command at R prompt:

fixInNamespace("node_barplot", pos="package:party")

接着,开始增加我们想要的东西:

  1. Add labels = NULL, gp = NULL to the existing list of arguments for that function.
  2. 在“条码”之后,在<条码>网(gp = 准备(填充=“透明”)之后,添加以下内容:

    if (!is.null(labels)) {
      labs <- as.character(labels[ctreeobj@where==node$nodeID])
      len <- length(labs)
      x <- unit(rep(0.5, len), "npc")
      y <- unit(0.5:len/len, "npc")
      for (i in 1:len) 
        grid.text(labs[i], x=x[i], y=y[i], just="center", gp=gp)
    }
    

    Here, the key idea is to select labels corresponding to the selected node (node$nodeID), and we can grab this information from the slot where of the ctree object (this is a vector indicating in which node each case ended up). The if test is just to ensure that we can use the function as originally written. The gp argument can be used to change font size or color.

对这项职能的一项典型呼吁是:

plot(cfit, tp_pars=list(labels=dfrm$names))

<代码>dfrm$names为数据框架的标签一栏,名称为dfrm。 下面是你数据的说明:

cfit <- ctree(young ~ age, data=a, 
              controls=ctree_control(minsplit=2, minbucket=2))
plot(cfit, tp_args=list(labels=a$names, gp=gpar(fontsize=8, col="darkgrey")))

“entergraph

问题回答

暂无回答




相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签