Active4 years, 1 month ago
Stem-and-Leaf Plots and Histograms 1 The stem-and-leaf plot shows the number of points scored by a college basketball player. Display the data in a histogram. The data ranges from 2 to 31. The data can be grouped into intervals of 10. Draw and label a horizontal and vertical axis. Include a title. Show the intervals on the horizontal axis. Label the vertical axis to show the frequencies. For each interval, count the number of data values from the stem-and-leaf plot. Double-click the one that you want to create the stem-and-leaf from and click OK. Your stem-and-leaf plot will appear in the Session window. Your stem-and-leaf plot will appear in the Session window. See this guide for more details on stem-and-leaf plots.
Is there a way to output a stem and leaf plot to a graphical device, such as
window()
/ quartz()
? There are at least two ways to get stem and leaf plots in R: ?stem, in the graphics package, and ?stem.leaf, in the aplpack package. Both output text to the console. For example: It would be nice if this could be conveniently output to a graphical device where it could be combined with other plots (say a histogram) in a multi-figure layout, and/or saved as a png file. I am aware that you can output LaTeX and compile it into a pdf (e.g., see: Stem and Leaf from R into LaTeX), but this isn't very convenient and isn't really what I'm after. Is there an R function that can do this? Is there a simple hand-coded solution?
Community♦
gunggung8,76066 gold badges4646 silver badges7171 bronze badges
2 Answers
Here is one simple example:
If you want to overlay a histogram then you probably want to use the
text
function on each of the elements of tmp
rather than paste
ing. Functions like strheight
and strwidth
will be useful to find the coordinates.There are also functions in the gplots and plotrix packages for plotting text and adding tables to plots (other functions in other packages probably exist along these lines as well).
Andrie143k3030 gold badges383383 silver badges452452 bronze badges
Greg SnowGreg Snow42k33 gold badges6363 silver badges9090 bronze badges
Following is equivalent:
For even more similar:
The code may need to be tweaked for different sets.
Using capture.output (as suggested by @Greg) and plotting with ggplot:
rnsornso13.4k1414 gold badges5252 silver badges118118 bronze badges