Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8230479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:09:03+00:00 2026-06-07T17:09:03+00:00

I created a binary classification tree using ctree. I would like each terminal node

  • 0

I created a binary classification tree using ctree. I would like each terminal node to contain the row names associated with that node. How can I accomplish this?

For example, for the dataset below, I would like the leftmost node to list the names of all those who are aged <23 (Abner to Abudemio) and the rightmost Abundiantus to Acelin respectively.

      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

. enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:09:05+00:00Added an answer on June 7, 2026 at 5:09 pm

    Here is one hacky solution. It involves very little modification in the original source code of the plotting functions from the party package. By reading the source code, I noticed that there is a terminal_panel which is calling node_barplot in case the outcome is a factor. (Everything is located in the R/plot.R function, if you have source package installed.) We can modify the later to display custom labels in the default bar chart.

    Just issue the following command at R prompt:

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

    and then, start adding what we want:

    1. Add labels = NULL, gp = NULL to the existing list of arguments for that function.
    2. Near the end of the function body, after grid.rect(gp = gpar(fill = "transparent")), add the following lines:

      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.

    A typical call to the function would now be:

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

    where dfrm$names is a column of labels from a data frame named dfrm. Here is an illustration with your data:

    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")))
    

    enter image description here

    (I have also tested this with the on-line example with the iris dataset.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a binary search tree, each node of my binary tree is setup
I have a binary tree class that is created with a root node and
I've already created the Binary Tree and Linked list classes, I'm just in need
Is it possible to load the CodeDOM from a .NET binary created using C#?
Using C#, I need to read a packed binary file created using FORTRAN. The
I'm using Ubuntu 10.04 and Qt4.6, and I've created an executable binary file on
I created a binary tree with some integer values, I can search the tree
I have a binary search tree created in C. The problem is I can't
I created a read / write of bytes into a binary file using fstream
I have to implement a binary search tree using C++ for one of assignments.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.