1

By now, if we do this:

library(vtree)

vtree(mtcars, "cyl am",
      sameline = TRUE, 
      follow=list(cyl="4"))

we get this: enter image description here

I would like to sort in descending order without manipulating the data. Is this possible?

Desired output:

enter image description here

TarJae
  • 72,363
  • 6
  • 19
  • 66

1 Answers1

3

I can't see a way of doing this in the vtree function, but you can swap the nodes in the output if that is any use to you?

vt <- vtree(mtcars, "cyl am",
            sameline = TRUE, 
            follow = list(cyl = "4"))

str2 <- str <- strsplit(vt$x$diagram, "\n")[[1]]

node5 <- grep("^Node_5", str)
node6 <- grep("^Node_6", str)

str2[node5] <- sub("Node_6", "Node_5", str[node6])
str2[node6] <- sub("Node_5", "Node_6", str[node5])

vt$x$diagram <- paste(str2, collapse = "\n")

vt

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87