1

I'm generating a composite graph in R which I've set up as 2x2. For the figures, I have 3 boxplots and would like for the last quadrant to contain some descriptive text about the graphs. A bit of Google-ing led me to create an empty plot with plot.new() and then use the plotrix package which allows me to build a table and put that into the graph. An example is below, along with some pseudo-code. The data and the actual figures in the pseudo-code are irrelevant - just placeholders to get to what I'm trying to accomlish.

The problem is that this isn't very attractive and I can't find any other way to create a block of text to occupy that last quadrant. I've tried changing the x and y coordinates for the table, which doesn't work since there are technically no coordinates in an empty plot other than 0,0. I've also tried increasing the font size with cex=##, but that just makes the lines run together.

Any tips are appreciated.

library('beeswarm')
library('plotrix')

d = data.frame('study' = c(rep('study1',25),rep('study2',25)))
d$res1 = c(rnorm(25,40,5),rnorm(25,50,10))
d$category = c(rep('yes',12),rep('no',13),rep('yes',13),rep('no',12))
opar = par(mfrow=c(2,2))

rng = range(d$res)
study1 = which(d$study == 'study1')

boxplot(d$res1[study1]~d$category[study1], pch=19, lwd=2, cex=1.5, outline=F, ylim=rng, main='Study 1')
beeswarm(d$res1[study1]~d$category[study1], pch=19, cex=1.5, col=c('red','blue'), add=T)

boxplot(d$res1[-study1]~d$category[-study1], pch=19, lwd=2, cex=1.5, outline=F, ylim=rng, main='Study 2')
beeswarm(d$res1[-study1]~d$category[-study1], pch=19, cex=1.5, col=c('red','blue'), add=T)

shps = rep(17,length(d$study))
shps[study1] = 19
boxplot(d$res1~d$category, pch=46, lwd=2, cex=1.5, outline=F, ylim=rng, main='Combined')
beeswarm(d$res1~d$category, pch=46, cex=1.5, col=c('red','blue'), add=T, pwpch=shps)
legend('topright',c('Study 1','Study 2'), pch=c(19,17), pt.cex=1.5)

plot.new()
tbldf = data.frame('p-value' =    c(0.33,0.40,0.85),
               'FDR' = c(0.84, 0.96, 0.97))
rownames(tbldf) = c('Study 1', 'Study 2', 'Combined')
addtable2plot(0, 0, tbldf, bty = "o", display.rownames = TRUE, 
          title = sprintf('Analyte'), vlines=T, cex=1.25)
par(opar)

What I get is something like this:

enter image description here

What I would like is more like this - the table is still a bit 'boring' but adequate for the purpose. Any improvements are welcome:

enter image description here

KirkD-CO
  • 1,603
  • 1
  • 22
  • 35
  • So if that's not "attractive" enough, what *specifically* do you want to change? What is your desired output? Also if you post code, make sure it's [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Where does the `beeswarm` function come from. Better to inline sample data because we cannot access "data.csv". If we can't run the code, we can't try different possible solutions. – MrFlick Sep 29 '14 at 02:42
  • Additional to what @MrFlick lamented on, perhaps another topic to discuss "why do you need to place this table of data in this fashion?" If this is to be published or turned in, I personally do not think this is the most appropriate way to put the table, whether you are formatting it in LaTeX or Word. (Both of which, by the way, can make tables that look considerably better than this one.) I do relish a challenge, though, so post some code/data and let us try it out. – r2evans Sep 29 '14 at 06:27
  • I've changed the code into a form that "should" run on its own. As for beewarm, that is an R package which generates the points on the boxplot to allow the data distribution to be visualized. The placement of the table is there because I need to show these results for a set of t-test (or other tests). I could use PowerPoint or Word to generate these - that's what I've done with the example of what I'm trying to accomplish. The problem there is that I have 140 figures like this to generate, each with its own results. I would rather not do that for each individual figure. – KirkD-CO Oct 05 '14 at 18:39

0 Answers0