[R] odfWeave: Some questions about potential formatting options

Paul Miller pjmiller_57 at yahoo.com
Tue Apr 16 19:15:57 CEST 2013


Hi Milan and Max,

Thanks to each of you for your reply to my post. Thus far, I've managed to find answers to some of the questions I asked initially.

I am now able to control the justification of the leftmost column in my tables, as well as to add borders to the top and bottom. I also downloaded Milan's revised version of odfWeave at the link below, and found that it does a nice job of controlling column widths.

http://nalimilan.perso.neuf.fr/transfert/odfWeave.tar.gz

There are some other things I'm still struggling with though. 

1. Is it possible to get odfTableCaption and odfFigureCaption to make the titles they produce bold? I understand it might be possible to accomplish this by changing something in the styles but am not sure what. If someone can give me a hint, I can likely do the rest.

2. Is there any way to get odfFigureCaption to put titles at the top of the figure instead of the bottom? I've noticed that odfTableCaption is able to do this but apparently not odfFigureCaption.

3. Is it possible to add special characters to the output? Below is a sample Kaplan-Meier analysis. There's a footnote in there that reads "Note: X2(1) = xx.xx, p = .xxxx". Is there any way to make the X a lowercase Chi and to superscript the 2? I did quite a bit of digging on this topic. It sounds like it might be difficult, especially if one is using Windows as I am.

Thanks,

Paul 

##################
#### Get data ####
##################

#### Load packages ####

require(survival)
require(MASS)

#### Sample analysis ####

attach(gehan)
gehan.surv <- survfit(Surv(time, cens) ~ treat, data= gehan, conf.type = "log-log")
print(gehan.surv)

survTable <- summary(gehan.surv)$table
survTable <- data.frame(Treatment = rownames(survTable), survTable, row.names=NULL)
survTable <- subset(survTable, select = -c(records, n.max))

##################
#### odfWeave ####
##################

#### Load odfWeave ####

require(odfWeave)

#### Modify StyleDefs ####

currentDefs <- getStyleDefs()

currentDefs$firstColumn$type <- "Table Column"
currentDefs$firstColumn$columnWidth <- "5 cm"
currentDefs$secondColumn$type <- "Table Column"
currentDefs$secondColumn$columnWidth <- "3 cm"

currentDefs$ArialCenteredBold$fontSize <- "10pt"
currentDefs$ArialNormal$fontSize <- "10pt"
currentDefs$ArialCentered$fontSize <- "10pt"
currentDefs$ArialHighlight$fontSize <- "10pt"

currentDefs$ArialLeftBold <- currentDefs$ArialCenteredBold
currentDefs$ArialLeftBold$textAlign <- "left"

currentDefs$cgroupBorder <- currentDefs$lowerBorder
currentDefs$cgroupBorder$topBorder <- "0.0007in solid #000000"

setStyleDefs(currentDefs)

#### Modify ImageDefs ####

imageDefs <- getImageDefs()
imageDefs$dispWidth <- 5.5
imageDefs$dispHeight<- 5.5
setImageDefs(imageDefs)

#### Modify Styles ####

currentStyles <- getStyles()
currentStyles$figureFrame <- "frameWithBorders"
setStyles(currentStyles)

#### Set odt table styles ####

tableStyles <- tableStyles(survTable, useRowNames = FALSE, header = "")
tableStyles$headerCell[1,] <- "cgroupBorder"
tableStyles$header[,1] <- "ArialLeftBold"
tableStyles$text[,1] <- "ArialNormal"
tableStyles$cell[2,] <- "lowerBorder"

#### Weave odt source file ####

fp <- "N:/Studies/HCRPC1211/Report/odfWeaveTest/"
inFile <- paste(fp, "testWeaveIn.odt", sep="")
outFile <- paste(fp, "testWeaveOut.odt", sep="")
odfWeave(inFile, outFile)

######################################
#### Contents of .odt source file ####
######################################

Here is a sample Kaplan-Meier table.

<<testKMTable, echo=FALSE, results = xml>>=
odfTableCaption(“A Sample Kaplan-Meier Analysis Table”)
odfTable(survTable, useRowNames = FALSE, digits = 3,
colnames = c("Treatment", "Number", "Events", "Median", "95% LCL", "95% UCL"),
colStyles = c("firstColumn", "secondColumn", "secondColumn", 
"secondColumn", "secondColumn", "secondColumn"),
styles = tableStyles)
odfCat(“Note: X2(1) = xx.xx, p = .xxxx”)
@

Here is a sample Kaplan-Meier graph.

<<testKMFig, echo=FALSE, fig = TRUE>>=
odfFigureCaption("A Sample Kaplan-Meier Analysis Graph", label = "Figure")
plot(gehan.surv, xlab = "Time", ylab= "Survivorship")
@



More information about the R-help mailing list