[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] org-babel R output table with plot
From: |
Feng Shu |
Subject: |
Re: [O] org-babel R output table with plot |
Date: |
Tue, 25 Mar 2014 08:00:06 +0800 |
User-agent: |
Gnus/5.13001 (Ma Gnus v0.10) Emacs/24.3.50 (gnu/linux) |
John Hendy <address@hidden> writes:
> On Mon, Mar 24, 2014 at 10:22 AM, Feng Shu <address@hidden> wrote:
>> Hi everyone
>>
>> I want to R output table with plot, I use a solution below,
>> Who can tell me other solutions?
>>
>
> I sort of follow the below, but I think it would be more helpful to
> describe what you *don't* like about the output below. In other words,
> what are you trying to achieve that is not working below?
>
It just suit my need, but I want to know more simper solution, which let
me type less code.
>
> John
>
>> 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:
>>
>>
>> --
>>
--