emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-babel R output table with plot
@ 2014-03-24 15:22 Feng Shu
  2014-03-24 17:36 ` John Hendy
  0 siblings, 1 reply; 5+ messages in thread
From: Feng Shu @ 2014-03-24 15:22 UTC (permalink / raw)
  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:


-- 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-03-27  4:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-24 15:22 org-babel R output table with plot Feng Shu
2014-03-24 17:36 ` John Hendy
2014-03-25  0:00   ` Feng Shu
2014-03-27  2:55     ` John Hendy
2014-03-27  4:27       ` Feng Shu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).