1
$\begingroup$

In R, stem() produces the graph with "stems" in ascending order. Is there a code for obtaining them in descending order?

Example:

stem (cars$dist)

The decimal point is 1 digit(s) to the right of the |:

   0 | 14004678
   2 | 002466668822244466
   4 | 002668024466
   6 | 046806
   8 | 04523
  10 | 
  12 | 0

The desired output:

  12 | 0
  10 | 
   8 | 04523
   6 | 046806
   4 | 002668024466
   2 | 002466668822244466
   0 | 14004678
$\endgroup$
2
$\begingroup$

Try to capture output, and modify it in a desired way:

rev.stem <- function(data){
  out <- capture.output(stem(data))
  out <- c(out[1:3], rev(out[4:length(out)]))
  cat(out, sep="\n")
}

rev.stem(cars$dist)
$\endgroup$
0
$\begingroup$

Thanks a lot, Sobach, for your solution works nicely for the stem function, and it also works for the stem.leaf.backback function (in the aplpack package). These two functions do not offer an option for showing descending values in the plot. Small numbers at the lower end, and bigger numbers at the upper end is probably the best way in this exploratory data analysis tool.

$\endgroup$
1
  • $\begingroup$ Welcome to datascience SO, please remove this answer and place it as a comment below the original answer. $\endgroup$
    – Stereo
    Oct 15 '16 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.