I really like R's stem function, it creates a stem-and-leaf plot right in the R console, no fancy graphics devices required! In a recent R-help post, Ralf Bierig presented a very nice ASCII scatterplot representing two densities. Unfortunately, I don't know of any R function that will generate this type of plot, but I will argue that they are very useful to quickly visualize data, and to present data in ASCII-only media, such as an R mailing list message.
I wrote a little prototype R function I am calling scat ( to compliment stem, and because the output may be somewhat 'crappy' ) to generate a simple ASCII scatterplot. I put the code on a wiki. Unfortunately, the spambots have forced me to disallow editing of the wiki :-(.
You can load the latest version of scat by downloading the file from the wiki, or the original from here scat.R, or within R with
> source("http://biostatmatt.com/R/scat.R")
Here are some examples (note: this doesn't work well unless you view the ASCII in a monospace font):
> data(co2) #Mauna Loa Atmospheric CO2 Concentration > scat(c(co2[1:75]), rows=10, cols=80) ____________________________________________________________________________________ | | | * | | * * *** | | * *** * * * * | | ** * * * * * * ** * | | * * * * * ** * * * | | * * * * * * * * * * | | ** * ** * * * * * ** | | * * * * ** * * ** | | * * * * | | ** ** | |____________________________________________________________________________________| > x <- sin(seq(0,2*pi,length.out=30)) > scat(x, cols=15, rows=8) ___________________ | | | * | | **** | | * * | | * * | | * ** * | | * * | | * * | | **** | |___________________| > library(MASS) > data(galaxies) #Velocities for 82 Galaxies > d <- density(galaxies) > scat(d$y, d$x) ______________________________________________________ | | | * | | ** | | **** | | * * | | * ** | | * *** | | * ** | | * * | | * * | | * * | | * * | | * * | | * * | | * * | | * ** | | * * | | *** ** ** | | ** ** * ** | | ** ** *** ** **** | | *** ******* ******** ******* | |______________________________________________________|
Matt, that's really handy! It would be nice if scat could handle missing values too. Thanks for sharing it.
Awesome! 😀
Might be also useful for people working on text terminals when displaying usual R graphics is impossible and printing to PDF/Postscript is not an option.
cool - planning on using this to add visual diagnostics to my log files
-S.
Hi Matt,
Wonderful (!) idea, thank you for sharing it.
There is another audience that will benefit from this - blind people who use R.
I wrote a bit on the subject here:
http://www.r-statistics.com/2010/05/helping-the-blind-use-r-by-exporting-r-console-to-word/
And I am glad you wrote this, and will forward this to the blind guy who initially made me thing about "R for the blind".
Best,
Tal
That's helpful; thanks. It's reminiscent of the "dumb" terminal in Gnuplot, which I've used to craft text-based emails that contained graphs.
Thanks to all!
Bill, I didn't know that Gnuplot had a "dumb" terminal. That's a thought, maybe R should have an Gnuplot graphics driver. I'm sure it's much more mature than 'scat'. I believe octave uses Gnuplot by default.
Tal, that's great, I hope it's helpful. I did see your post. See also what I mentioned to Bill above.
Matt, see http://makingsense.facilitatedsystems.com/2007/03/making-musical-sense-by-email-table-of.html and especially http://facilitatedsystems.com/weblog/2007/03/making-musical-sense-by-email-part-2.html.
Incidentally, J does have a Gnuplot interface.