[R] odfWeave: Some questions about potential formatting options
Milan Bouchet-Valat
nalimilan at club.fr
Wed Apr 17 18:17:21 CEST 2013
Le mardi 16 avril 2013 à 10:15 -0700, Paul Miller a écrit :
> 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.
Just right-click on a caption and choose "Edit paragraph style..." (in
the template document). Or edit the styles called Table and
Illustration.
> 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.
No idea.
> 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.
For the Chi you can copy the Unicode character χ from e.g. LibreOffice
and use it in the string passed to odfCat() and friends. If that does
not work on Windows, you can also use the escape code \u03C7.
For the ², you can either use the Unicode character (code \u00B2), or
try to insert ODF markup to put a 2 as an exponent (I did not test
second option).
Regards
> 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