Re: [R] Figures within tables [slightly off-topic]

2010-04-13 Thread Jim Lemon

On 04/13/2010 06:07 AM, Peter Jepsen wrote:

Dear R-listers



I am writing a manuscript for a scientific journal in clinical medicine.
I have three groups of patients, and I present a 10*3 table of their
characteristics in Table 1. Some of their characteristics, e.g. their
age, are on a continuous scale, others are dichotomous. I am thinking of
presenting the age distribution in each group as miniature graphs, each
of which must fit in one table cell. I am hoping that someone can answer
these questions:



1. Has anybody ever seen something like this published anywhere?

2. Should I draw the entire table as a figure, or should I make a table
in Word (or similar) and manually insert the graphs in their cells?

3. Are there R packages that can draw tables?

4. And one for you editors out there: Would such a table count as one
figure, several figures, or a table?!



Forgive me for being somewhat off-topic. I hope for your help anyway.


Hi Peter,
This sounds like Edward Tufte's sparklines and I think there was a 
discussion of this sort of graphic a couple of years ago. Yep, see:


http://finzi.psych.upenn.edu/R/Rhelp02/archive/76508.html

Jim

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Figures within tables [slightly off-topic]

2010-04-13 Thread Ted Harding
On 13-Apr-10 09:54:20, Jim Lemon wrote:
 On 04/13/2010 06:07 AM, Peter Jepsen wrote:
 Dear R-listers

 I am writing a manuscript for a scientific journal in clinical
 medicine. I have three groups of patients, and I present a 10*3
 table of their characteristics in Table 1. Some of their
 characteristics, e.g. their age, are on a continuous scale,
 others are dichotomous. I am thinking of presenting the age
 distribution in each group as miniature graphs, each of which
 must fit in one table cell. I am hoping that someone can
 answer these questions:

 1. Has anybody ever seen something like this published anywhere?

 2. Should I draw the entire table as a figure, or should I make
 a table in Word (or similar) and manually insert the graphs in
 their cells?

 3. Are there R packages that can draw tables?

 4. And one for you editors out there: Would such a table count
 as one figure, several figures, or a table?!

 Forgive me for being somewhat off-topic. I hope for your help anyway.

 Hi Peter,
 This sounds like Edward Tufte's sparklines and I think there
 was a discussion of this sort of graphic a couple of years ago.
 Yep, see:
 
 http://finzi.psych.upenn.edu/R/Rhelp02/archive/76508.html
 
 Jim

It does indeed sound like sparklines! In the posting by Robin
Hankin that Jim refers to, the URL for Tufte's illustration of
sparklines is:

http://www.edwardtufte.com/bboard/
q-and-a-fetch-msg?msg_id=0001ORtopic_id=1

[equivalently: http://tinyurl.com/6bbkw ]

Robin posted that he would send privately to the original poster
examples of how to do it in Sweave. It could be useful if Robin
could provide a pointer to on-line examples of such usage.

In general, the key to getting that sort of thing right is to
prepare the graphic beforehand as an Encapsulated PostScript (EPS)
file, which R can do very nicely. This can then be imported into
document-preparation software which can handle EPS files properly.
LaTeX can do that, also the classic groff (always present on Linux
systems). Maybe Word can, but don't ask me about that; however,
if you live in that world then R should be able to produce Windows
Metafiles (WMF) of graphics which could then be imported.

The point here is that an EPS file contains a %%BoundingBox line
which states what the dimensions of the graphic are in terms of
the within-file coordinate system (specifically, location of
lower left and upper right corners). The important thing about
that is that the software which produces the EPS file should
compute a good BoundingBox -- if that is wrong, then the result
can be awful. R is good at that, though you may need to tweak
things using relevant options in the postscript() command. You
may even need to explicitly edit the %%BoundingBox line in the
EPS file to get it exactly as you want it!

Once that is available, the document software will alow you to
specify somehow the dimensions of the graphic as it will appear
in the text. I'm no expert on LaTeX, so can't discuss details
of this. Maybe other will; maybe Robin's examples will explain.

In groff, however, you can specify these directly, or indirectly
via a macro, and then import the graphic where you want; and you
can even define a special character which will display as the
graphic and will also have the same status as any ther character
(e.g. the letter A) and be automatically placed, and scaled
according to the current text point size, just like an ordinary
text character.

Either way, there is no problem putting a graphic into a cell
in a table.

As it happens, I received via the groff mailing-list a few months
ago a query from someone who precisely wanted to implement Tufte
sparklines in running text. He provided and example of text and
of a sparkline graphic. I was then able to create an example of
how this works in groff. He gave permission for his example and
the graphic to be used in communicating the method communicated
to others, so I have placed on my website

A: An explanation of how it is done, with illustrations using
   his EPS graphic:

   http://www.zen89632.zen.co.uk/Misc/do_spark_howto.pdf

B: The example EPS file he provided:

   http://www.zen89632.zen.co.uk/Misc/spark.average.fund.size.eps

Note that, owing to peculiarites of the graphic (in particular
rthe X-axis) it does not render well in the PDF file -- you may
need to zoom to 200% to see it properly.

This is an example of importing an EPS file into running text,
with adjustable vertical and horizontal dimensions, in other
words a true Tufte sparkline.

Hoping this helps, at least for explanation!

As to what editors may think of it -- Is it text? Is it graphics?
Is it a table? I just don't know. They tick their own boxes.
It is certainly playing the *rĂ´le* of text, but the fact that
there needs to be a graphics (e.g. EPS) file present in order
for it to work means that their graphics light may flash red.
And in your application it is certainly occurring in the context
of a table. I'd go for table myself (with 

[R] Figures within tables [slightly off-topic]

2010-04-12 Thread Peter Jepsen
Dear R-listers

 

I am writing a manuscript for a scientific journal in clinical medicine.
I have three groups of patients, and I present a 10*3 table of their
characteristics in Table 1. Some of their characteristics, e.g. their
age, are on a continuous scale, others are dichotomous. I am thinking of
presenting the age distribution in each group as miniature graphs, each
of which must fit in one table cell. I am hoping that someone can answer
these questions:

 

1. Has anybody ever seen something like this published anywhere?

2. Should I draw the entire table as a figure, or should I make a table
in Word (or similar) and manually insert the graphs in their cells?

3. Are there R packages that can draw tables?

4. And one for you editors out there: Would such a table count as one
figure, several figures, or a table?!

 

Forgive me for being somewhat off-topic. I hope for your help anyway.

 

Best regards,

Peter.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Figures within tables [slightly off-topic]

2010-04-12 Thread Erik Iverson

Hello,


I am writing a manuscript for a scientific journal in clinical medicine.
I have three groups of patients, and I present a 10*3 table of their
characteristics in Table 1. Some of their characteristics, e.g. their
age, are on a continuous scale, others are dichotomous. I am thinking of
presenting the age distribution in each group as miniature graphs, each
of which must fit in one table cell. I am hoping that someone can answer
these questions:

 


1. Has anybody ever seen something like this published anywhere?

2. Should I draw the entire table as a figure, or should I make a table
in Word (or similar) and manually insert the graphs in their cells?



Depending on your needs, there's another solution. You could output 
LaTeX, and compile that to a PDF.  The first thing I thought of when I 
read your topic was the describe function in Hmisc.  The help file for 
?describe references


 http://biostat.mc.vanderbilt.edu/twiki/pub/Main/Hmisc/counties.pdf

Probably not exactly what you're looking for, but it might be start. See 
also:


http://texblog.wordpress.com/2008/02/04/placing-graphicsimages-inside-a-table/

I would probably go this route, generating code to produce a LaTeX table 
and the associated image files.  I've also used low-level grid graphics 
function calls (e.g., grid.text ) to produce 'tables' with hazard ratio 
type graphics included as a column. (a 'forest plot').


Hope that helps,
Erik

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Figures within tables [slightly off-topic]

2010-04-12 Thread baptiste auguie
Hi,

On 12 April 2010 22:07, Peter Jepsen p...@dce.au.dk wrote:

 3. Are there R packages that can draw tables?

the gplots package has a textplot() function, and the gridExtra
package a tableGrob(),

http://rwiki.sciviews.org/doku.php?id=tips:graphics-grid:table

In theory it should be possible to adapt the latter to allow the
placement of a (preferably lattice / ggplot2 / Grid) graphic in the
desired cells.

HTH,

baptiste

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.