2

I would like to highlight the subset of the given set on graphic output of stem-and-leaf display in R, viz:

library(fmsb)
xs <- c(rep(10,3), rep(20, 2), rep(30, 5))
gstem(xs)

xs_to_highlight <- c(10, 30)

The highlight of 10 and 30 can be in colour, underline etc. No strict requirements.

Artem
  • 3,304
  • 3
  • 18
  • 41
  • No strict requirement, eh? How about we give you a requirement...tell us the nature of your console or the output target. – IRTFM May 12 '16 at 17:02
  • Basically there is really no requirement how to highlight indicated numbers. I am not interested in console output but in graph window output. – Artem May 12 '16 at 17:57

1 Answers1

1

One possibility would be to use a back to back stem and leaf plot, with the X's to be highlighted on one side, and the rest on the other side. The ?stem.leaf.backback function in the aplpack package can do this for you. All you really need to do is write some code to extract the highlighted values from the rest. Consider:

library(aplpack)
xs              <- c(rep(10,3), rep(20, 2), rep(30, 5))
xs_to_highlight <- c(10, 30)
other_xs        <- xs[-match(xs_to_highlight, xs)]
stem.leaf.backback(x=xs_to_highlight, y=other_xs, m=1)
# ____________________________
#   1 | 2: represents 12, leaf unit: 1 
# xs_to_highlight
#                 other_xs
# ____________________________
#   1       0| 1 |00     2   
#            | 2 |00    (2)  
#   1       0| 3 |0000   4   
# ____________________________
# n:        2     8      
# ____________________________
gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79