[R] Examples of advanced data visualization
Yihui Xie
xieyihui at gmail.com
Sun Nov 30 08:48:27 CET 2008
For the motion chart, I've written a quick example in R (for the
Brownian Motion):
## put random numbers in Google API
# n: number of movie frames
# p: number of points
g.brownian.motion = function(n = 50, p = 20, start = 1900,
digits = 14, file = "brownian.motion.html", width = 800,
height = 600) {
x = round(c(t(apply(matrix(rnorm(p * n), p, n), 1, cumsum))),
digits)
y = round(c(t(apply(matrix(rnorm(p * n), p, n), 1, cumsum))),
digits)
tmp = character(p * n * 4)
tmp[seq(1, p * n * 4, 4)] = shQuote(formatC(rep(1:p, n),
width = nchar(p), flag = 0))
tmp[seq(2, p * n * 4, 4)] = rep(start + (1:n), each = p)
tmp[seq(3, p * n * 4, 4)] = x
tmp[seq(4, p * n * 4, 4)] = y
cat(c("<html>", " <head>", " <script type=\"text/javascript\"
src=\"http://www.google.com/jsapi\"></script>",
" <script type=\"text/javascript\">", "
google.load(\"visualization\", \"1\", {packages:[\"motionchart\"]});",
" google.setOnLoadCallback(drawChart);", " function
drawChart() {",
" var data = new google.visualization.DataTable();"),
paste(" data.addRows(", p * n, ");", sep = ""),
c(" data.addColumn('string', 'point');", "
data.addColumn('number', 'year');",
" data.addColumn('number', 'X');", "
data.addColumn('number', 'Y');"),
paste(" data.setValue(", rep(0:(p * n - 1), each = 4),
", ", rep(0:3, p * n), ", ", tmp, ");", sep = "",
collapse = "\n"), c(" var chart = new
google.visualization.MotionChart(document.getElementById('chart_div'));"),
paste(" chart.draw(data, {width: ", width, ", height: ",
height, "});\", \" }", sep = ""), c(" </script>",
" </head>", "", " <body>"), paste(" <div
id=\"chart_div\" style=\"width: ",
width, "px; height: ", height, "px;\"></div>", sep = ""),
c(" </body>", "</html>"), file = file, sep = "\n")
}
# for example:
g.brownian.motion(50, 15, digits = 2, width = 600, height = 500)
# see http://www.yihui.name/en/post/57.htm for the motion
##
As you can see, it just makes use of the GoogleVis API, as R has no
internal support for producing a Flash movie. However, there are other
add-on packages for dynamic graphics, such as rggobi / iplots, etc.
See the Graphics task view on CRAN.
Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
Mobile: +86-15810805877
Homepage: http://www.yihui.name
School of Statistics, Room 1037, Mingde Main Building,
Renmin University of China, Beijing, 100872, China
On Sat, Nov 29, 2008 at 12:53 AM, David Winsemius
<dwinsemius at comcast.net> wrote:
> The gapminder.org project ;
>
> http://graphs.gapminder.org/world/
>
> Hans Rosling at TED:
>
> http://www.ted.com/index.php/talks/hans_rosling_shows_the_best_stats_you_ve_ever_seen.html
>
> http://hdr.undp.org/external/gapminder/2004/hdr2004.html
>
> And was given Google support last year:
> http://googleblog.blogspot.com/2007/03/world-in-motion.html
>
> -- David Winsemius
>
>
> On Nov 28, 2008, at 10:55 AM, Hans W. Borchers wrote:
>
>> Dear R-help,
>>
>> I am looking for ideas and presentations of new and advanced data
>> visualization
>> methods. As an example of what I am searching for, the 'Many Eyes' pages
>> at
>>
>> http://manyeyes.alphaworks.ibm.com/manyeyes/
>>
>> may provide a good paradigm. I would be interested even if it will not be
>> easy
>> to implement such examples in R, e.g. because of the interactive nature of
>> these
>> graphical displays.
>>
>> Please answer to my e-mail address. In case enough interesting material
>> comes
>> up, I will enter a summary here.
>>
>> Hans Werner Borchers
>> ABB Corporate Research
>>
More information about the R-help
mailing list