Changing Variable Labels in 'ctree' plot












0















I'm struggling to try to make a CI tree from the 'party' package in R look presentable. So far this is what I have, in terms of cleaning the tree up.



current version of tree



What I would like to do is change the variable names on each individual node to something more descriptive and not just the shortened variable names used for coding. I tried changing the variable names themselves using the following code:



colnames(dat.long.imp.m)[colnames(dat.long.imp.m)=="Gender"] <- "sex"


Because some of the variable names contained spaces, I had to enter them into the 'ctree' function the following way:



ctree(formula = DV ~ "`Executive Copartisan`" 


But this gave me an error: Error: attempt to use zero-length variable name. So instead I tried to use the 'apply_labels' function from the 'expss' package, but the labels didn't actually get applied in the ctree plot (as can be seen from the screen grab).



Is there any way to change these variable names to something more descriptive that might include spaces?










share|improve this question





























    0















    I'm struggling to try to make a CI tree from the 'party' package in R look presentable. So far this is what I have, in terms of cleaning the tree up.



    current version of tree



    What I would like to do is change the variable names on each individual node to something more descriptive and not just the shortened variable names used for coding. I tried changing the variable names themselves using the following code:



    colnames(dat.long.imp.m)[colnames(dat.long.imp.m)=="Gender"] <- "sex"


    Because some of the variable names contained spaces, I had to enter them into the 'ctree' function the following way:



    ctree(formula = DV ~ "`Executive Copartisan`" 


    But this gave me an error: Error: attempt to use zero-length variable name. So instead I tried to use the 'apply_labels' function from the 'expss' package, but the labels didn't actually get applied in the ctree plot (as can be seen from the screen grab).



    Is there any way to change these variable names to something more descriptive that might include spaces?










    share|improve this question



























      0












      0








      0








      I'm struggling to try to make a CI tree from the 'party' package in R look presentable. So far this is what I have, in terms of cleaning the tree up.



      current version of tree



      What I would like to do is change the variable names on each individual node to something more descriptive and not just the shortened variable names used for coding. I tried changing the variable names themselves using the following code:



      colnames(dat.long.imp.m)[colnames(dat.long.imp.m)=="Gender"] <- "sex"


      Because some of the variable names contained spaces, I had to enter them into the 'ctree' function the following way:



      ctree(formula = DV ~ "`Executive Copartisan`" 


      But this gave me an error: Error: attempt to use zero-length variable name. So instead I tried to use the 'apply_labels' function from the 'expss' package, but the labels didn't actually get applied in the ctree plot (as can be seen from the screen grab).



      Is there any way to change these variable names to something more descriptive that might include spaces?










      share|improve this question
















      I'm struggling to try to make a CI tree from the 'party' package in R look presentable. So far this is what I have, in terms of cleaning the tree up.



      current version of tree



      What I would like to do is change the variable names on each individual node to something more descriptive and not just the shortened variable names used for coding. I tried changing the variable names themselves using the following code:



      colnames(dat.long.imp.m)[colnames(dat.long.imp.m)=="Gender"] <- "sex"


      Because some of the variable names contained spaces, I had to enter them into the 'ctree' function the following way:



      ctree(formula = DV ~ "`Executive Copartisan`" 


      But this gave me an error: Error: attempt to use zero-length variable name. So instead I tried to use the 'apply_labels' function from the 'expss' package, but the labels didn't actually get applied in the ctree plot (as can be seen from the screen grab).



      Is there any way to change these variable names to something more descriptive that might include spaces?







      r ctree expss






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 18:57









      Gregory Demin

      2,08211216




      2,08211216










      asked Jan 1 at 21:28









      KaitlinKaitlin

      33




      33
























          1 Answer
          1






          active

          oldest

          votes


















          0














          ctree function is from 'party' package which is not labels-aware. To utilize labels in such cases you need use_labels function. See vignette for details - Variables and value labels support. Example:



          library(expss)
          library(party)
          data(mtcars)
          mtcars = apply_labels(mtcars,
          mpg = "Miles/(US) gallon",
          cyl = "Number of cylinders",
          disp = "Displacement (cu.in.)",
          hp = "Gross horsepower",
          drat = "Rear axle ratio",
          wt = "Weight (1000 lbs)",
          qsec = "1/4 mile time",
          vs = "Engine",
          am = "Transmission",
          gear = "Number of forward gears",
          carb = "Number of carburetors"
          )

          res = use_labels(mtcars,
          ctree(hp ~ cyl + carb, # or hp ~ .
          controls = ctree_control(minsplit = 1),
          data = ..data) # ..data is placeholder for 'mtcars' dataset
          )

          plot(res)


          enter image description here






          share|improve this answer


























          • Thank you very much, this worked! I had a feeling it had something to do with the label compatibility of the 'ctree' function so thank you for clearing that up!

            – Kaitlin
            Jan 3 at 16:32











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999073%2fchanging-variable-labels-in-ctree-plot%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          ctree function is from 'party' package which is not labels-aware. To utilize labels in such cases you need use_labels function. See vignette for details - Variables and value labels support. Example:



          library(expss)
          library(party)
          data(mtcars)
          mtcars = apply_labels(mtcars,
          mpg = "Miles/(US) gallon",
          cyl = "Number of cylinders",
          disp = "Displacement (cu.in.)",
          hp = "Gross horsepower",
          drat = "Rear axle ratio",
          wt = "Weight (1000 lbs)",
          qsec = "1/4 mile time",
          vs = "Engine",
          am = "Transmission",
          gear = "Number of forward gears",
          carb = "Number of carburetors"
          )

          res = use_labels(mtcars,
          ctree(hp ~ cyl + carb, # or hp ~ .
          controls = ctree_control(minsplit = 1),
          data = ..data) # ..data is placeholder for 'mtcars' dataset
          )

          plot(res)


          enter image description here






          share|improve this answer


























          • Thank you very much, this worked! I had a feeling it had something to do with the label compatibility of the 'ctree' function so thank you for clearing that up!

            – Kaitlin
            Jan 3 at 16:32
















          0














          ctree function is from 'party' package which is not labels-aware. To utilize labels in such cases you need use_labels function. See vignette for details - Variables and value labels support. Example:



          library(expss)
          library(party)
          data(mtcars)
          mtcars = apply_labels(mtcars,
          mpg = "Miles/(US) gallon",
          cyl = "Number of cylinders",
          disp = "Displacement (cu.in.)",
          hp = "Gross horsepower",
          drat = "Rear axle ratio",
          wt = "Weight (1000 lbs)",
          qsec = "1/4 mile time",
          vs = "Engine",
          am = "Transmission",
          gear = "Number of forward gears",
          carb = "Number of carburetors"
          )

          res = use_labels(mtcars,
          ctree(hp ~ cyl + carb, # or hp ~ .
          controls = ctree_control(minsplit = 1),
          data = ..data) # ..data is placeholder for 'mtcars' dataset
          )

          plot(res)


          enter image description here






          share|improve this answer


























          • Thank you very much, this worked! I had a feeling it had something to do with the label compatibility of the 'ctree' function so thank you for clearing that up!

            – Kaitlin
            Jan 3 at 16:32














          0












          0








          0







          ctree function is from 'party' package which is not labels-aware. To utilize labels in such cases you need use_labels function. See vignette for details - Variables and value labels support. Example:



          library(expss)
          library(party)
          data(mtcars)
          mtcars = apply_labels(mtcars,
          mpg = "Miles/(US) gallon",
          cyl = "Number of cylinders",
          disp = "Displacement (cu.in.)",
          hp = "Gross horsepower",
          drat = "Rear axle ratio",
          wt = "Weight (1000 lbs)",
          qsec = "1/4 mile time",
          vs = "Engine",
          am = "Transmission",
          gear = "Number of forward gears",
          carb = "Number of carburetors"
          )

          res = use_labels(mtcars,
          ctree(hp ~ cyl + carb, # or hp ~ .
          controls = ctree_control(minsplit = 1),
          data = ..data) # ..data is placeholder for 'mtcars' dataset
          )

          plot(res)


          enter image description here






          share|improve this answer















          ctree function is from 'party' package which is not labels-aware. To utilize labels in such cases you need use_labels function. See vignette for details - Variables and value labels support. Example:



          library(expss)
          library(party)
          data(mtcars)
          mtcars = apply_labels(mtcars,
          mpg = "Miles/(US) gallon",
          cyl = "Number of cylinders",
          disp = "Displacement (cu.in.)",
          hp = "Gross horsepower",
          drat = "Rear axle ratio",
          wt = "Weight (1000 lbs)",
          qsec = "1/4 mile time",
          vs = "Engine",
          am = "Transmission",
          gear = "Number of forward gears",
          carb = "Number of carburetors"
          )

          res = use_labels(mtcars,
          ctree(hp ~ cyl + carb, # or hp ~ .
          controls = ctree_control(minsplit = 1),
          data = ..data) # ..data is placeholder for 'mtcars' dataset
          )

          plot(res)


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 2 at 11:24

























          answered Jan 1 at 23:13









          Gregory DeminGregory Demin

          2,08211216




          2,08211216













          • Thank you very much, this worked! I had a feeling it had something to do with the label compatibility of the 'ctree' function so thank you for clearing that up!

            – Kaitlin
            Jan 3 at 16:32



















          • Thank you very much, this worked! I had a feeling it had something to do with the label compatibility of the 'ctree' function so thank you for clearing that up!

            – Kaitlin
            Jan 3 at 16:32

















          Thank you very much, this worked! I had a feeling it had something to do with the label compatibility of the 'ctree' function so thank you for clearing that up!

          – Kaitlin
          Jan 3 at 16:32





          Thank you very much, this worked! I had a feeling it had something to do with the label compatibility of the 'ctree' function so thank you for clearing that up!

          – Kaitlin
          Jan 3 at 16:32




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999073%2fchanging-variable-labels-in-ctree-plot%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Mossoró

          Error while reading .h5 file using the rhdf5 package in R

          Pushsharp Apns notification error: 'InvalidToken'