From mboxrd@z Thu Jan 1 00:00:00 1970 From: Feng Shu Subject: org-babel R output table with plot Date: Mon, 24 Mar 2014 23:22:08 +0800 Message-ID: <87txan8vvj.fsf@news.tumashu-localhost.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WS6mw-0000Pk-8a for emacs-orgmode@gnu.org; Mon, 24 Mar 2014 11:27:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WS6mr-0007lT-AQ for emacs-orgmode@gnu.org; Mon, 24 Mar 2014 11:27:46 -0400 Received: from mail-pa0-x230.google.com ([2607:f8b0:400e:c03::230]:61199) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WS6mr-0007lP-3T for emacs-orgmode@gnu.org; Mon, 24 Mar 2014 11:27:41 -0400 Received: by mail-pa0-f48.google.com with SMTP id hz1so5583350pad.7 for ; Mon, 24 Mar 2014 08:27:40 -0700 (PDT) Received: from news.tumashu-localhost.org ([120.4.235.135]) by mx.google.com with ESMTPSA id gu11sm33809708pbd.74.2014.03.24.08.27.30 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 24 Mar 2014 08:27:39 -0700 (PDT) Received: from feng by news.tumashu-localhost.org with local (Exim 4.80) (envelope-from ) id 1WS6hU-0001Tu-Mc for emacs-orgmode@gnu.org; Mon, 24 Mar 2014 23:22:08 +0800 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: orgmode Hi everyone I want to R output table with plot, I use a solution below, Who can tell me other solutions? thanks! #+begin_src R :results output raw drawer require("ascii") print.org <- function (x, caption) { print(paragraph(paste("#+CAPTION: ", caption, sep="")),type="org") print(ascii(x),type="org") } plot.org <- function (x, caption) { pngfile <- paste(caption, ".png", sep="") print(paragraph(paste("#+CAPTION: ", caption, sep="")),type="org") png(pngfile) plot(x) dev.off() print(paragraph(paste("[[./", pngfile, "]]", sep=""),new=FALSE),type="org") } data <- data.frame(x=c(1,20,100,800),y=c(200,4,5,29)) print.org(data, "test-table1") print.org(data, "test-table2") plot.org(data, "test-pic") #+end_src #+RESULTS: :RESULTS: #+CAPTION: test-table1 | | x | y | |---+--------+--------| | 1 | 1.00 | 200.00 | | 2 | 20.00 | 4.00 | | 3 | 100.00 | 5.00 | | 4 | 800.00 | 29.00 | #+CAPTION: test-table2 | | x | y | |---+--------+--------| | 1 | 1.00 | 200.00 | | 2 | 20.00 | 4.00 | | 3 | 100.00 | 5.00 | | 4 | 800.00 | 29.00 | #+CAPTION: test-pic [[./test-pic.png]] :END: --