Publications by Yihui Xie
Identify Data Points in Off-Screen R Graphics Devices
Today Ruya Gokhan Kocer asked me how to use the R function identify() in off-screen graphics devices. Actually it’s pretty easy as long as we obtain the list returned by identify(pos = TRUE). For example, Downdload the file here # open a windows device x11() x = rnorm(20) y = rnorm(20) plot(x, y) # identify 5 points id = identify(x, y, n = 5, p...
826 sym Python (345 sym/1 pcs)
Enhanced tidy.source() (Preserve Some Comments)
After a few hours’ work, I modified the function tidy.source() in the animation package so that it can preserve complete comment lines. See the tidy.source() wiki page for example. Downdload the R code here tidy.source <- function(source = "clipboard", keep.comment = TRUE, keep.blank.line = FALSE, begin.comment, end.comment, ...) { # parse ...
930 sym R (2016 sym/1 pcs)
Creating Tag Cloud Using R and Flash / JavaScript (SWFObject)
Tag cloud is a bunch of words drawn in a graph with their sizes proportional to their frequency; it’s widely used in blogs to visualize tags. We can observe important words quickly from a tag cloud, as they often appear in large fontsize. Tony N. Brown asked how to “graphically represent frequency of words in a speech” the other day in R-he...
4913 sym R (4999 sym/5 pcs) 8 img
Simulation of Burning Fire in R
Linlin Yan posted a cool (hot?) simulation of burning fire with R in the COS forum yesterday, which was indeed a warm welcome. I’m not sure whether our forum members will be scared by the “fire” under the title “Welcome to COS Forum”. The fire was mainly created by the function image() with carefully designed rows and columns in heate...
1822 sym R (1048 sym/2 pcs) 4 img
Counterintuitive Results in Flipping Coins
Coin-flipping is a rather old topic in probability theory, so most of us think we know very well about it, however, the other day I saw a question about this old topic (in David Smith’s REvolution?) which was beyond me expectation: how many times do we need to flip the coin until we get a sequence of HTH and HTT respectively? (For example, for ...
1497 sym R (723 sym/1 pcs) 2 img
Formatting Decimals in Texts with R
Yanping Chen raised a question in the Chinese COS forum on the output of Eviews: how to (re)format the decimal coefficients in equations as text output? For example, we want to round the numbers in CC = 16.5547557654 + 0.0173022117998*PP + 0.216234040485 * PP(-1) + 0.810182697599 * (WP + WG) to the 3rd decimal places. This can be simply done by r...
1588 sym R (1386 sym/2 pcs) 2 img
How to Import MS Excel Data into R
As Sir Francis Bacon said, “Histories make men wise; poets witty; the mathematics subtile; natural philosophy deep; moral grave; logic and rhetoric able to contend.” And Windows stupid. He should have added the last sentence if he were a Windows user in this age. 1. Avoid Using M$ Excel A lot of R users often ask this question: “How to impo...
4719 sym R (720 sym/2 pcs) 2 img
50000 Revisions Committed to R
Today Romain Francois posted an interesting topic in the R-help list, and you can read his blog post for more details: celebrating R commit #50000. 50000 is certainly not a small number; we do owe R core members a big “thank you” for their great efforts in this fantastic statistical language in the 13 years. When I saw Romain’s data, I sudd...
2261 sym R (1925 sym/3 pcs) 4 img
Some Interesting Packages in R: swfDevice, RGoogleTrends, FlashMXML, SVGAnnotation
I love R because there are always exciting new packages which can be far beyond your imagination. Here I’d like to introduce a couple of packages that look really awesome: 1. swfDevice: R graphics device for SWF output (by Cameron Bracken) This package is still at a pre-alpha stage but you can see a sketch now in R-Forge: https://r-forge.r-proj...
2662 sym
Create Animations in PDF Documents Using R
Since animation 1.0-9, we will be able to create a PDF document with an animation embedded in it; the function is saveLatex(), and its usage is similar to saveMovie() and saveSWF(): you pass an R expression for creating animations to this function, and this expression will be evaluated in the function; the image frames get recorded by a graphics ...
1896 sym R (559 sym/1 pcs)