latexTherm: Create LaTeX Thermometers and Colored Needles

Description Usage Arguments Author(s) Examples

View source: R/latexTherm.s

Description

latexTherm creates a LaTeX picture environment for drawing a series of thermometers whose heights depict the values of a variable y assumed to be scaled from 0 to 1. This is useful for showing fractions of sample analyzed in any table or plot, intended for a legend. For example, four thermometers might be used to depict the fraction of enrolled patients included in the current analysis, the fraction randomized, the fraction of patients randomized to treatment A being analyzed, and the fraction randomized to B being analyzed. The picture is placed inside a LaTeX macro definition for macro variable named name, to be invoked by the user later in the LaTeX file using name preceeded by a backslash.

If y has an attribute "table", it is assumed to contain a character string with LaTeX code. This code is used as a tooltip popup for PDF using the LaTeX ocgtools package or using style tooltips. Typically the code will contain a tabular environment. The user must define a LaTeX macro tooltipn that takes two arguments (original object and pop-up object) that does the pop-up.

latexNeedle is similar to latexTherm except that vertical needles are produced and each may have its own color. A grayscale box is placed around the needles and provides the 0-1 y-axis reference. Horizontal grayscale grid lines may be drawn.

pngNeedle is similar to latexNeedle but is for generating small png graphics. The full graphics file name is returned invisibly.

Usage

1
2
3
4
5
6
7
8
latexTherm(y, name, w = 0.075, h = 0.15, spacefactor = 1/2, extra = 0.07,
           file = "", append = TRUE)

latexNeedle(y, x=NULL, col='black', href=0.5, name, w=.05, h=.15,
            extra=0, file = "", append=TRUE)

pngNeedle(y, x=NULL, col='black', href=0.5, lwd=3.5, w=6, h=18,
          file=tempfile(fileext='.png'))

Arguments

y

a vector of 0-1 scaled values. Boxes and their frames are omitted for NA elements

x

a vector corresponding to y giving x-coordinates. Scaled accordingly, or defaults to equally-spaced values.

name

name of LaTeX macro variable to be defined

w

width of a single box (thermometer) in inches. For latexNeedle and pngNeedle is the spacing between needles, the latter being in pixels.

h

height of a single box in inches. For latexNeedle and pngNeedle is the height of the frame, the latter in pixels.

spacefactor

fraction of w added for extra space between boxes for latexTherm

extra

extra space in inches to set aside to the right of and above the series of boxes or frame

file

name of file to which to write LaTeX code. Default is the console. Also used as base file name for png graphic. Default for that is from tempfile.

append

set to FALSE to write over file

col

a vector of colors corresponding to positions in y. col is repeated if too short.

href

values of y (0-1) for which horizontal grayscale reference lines are drawn for latexNeedle and pngNeedle. Set to NULL to not draw any reference lines

lwd

line width of needles for pngNeedle

Author(s)

Frank Harrell

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Not run: 
# The following is in the Hmisc tests directory
# For a knitr example see latexTherm.Rnw in that directory
ct <- function(...) cat(..., sep='')
ct('\documentclass{report}\begin{document}\n')
latexTherm(c(1, 1, 1, 1), name='lta')
latexTherm(c(.5, .7, .4, .2), name='ltb')
latexTherm(c(.5, NA, .75, 0), w=.3, h=1, name='ltc', extra=0)
latexTherm(c(.5, NA, .75, 0), w=.3, h=1, name='ltcc')
latexTherm(c(0, 0, 0, 0), name='ltd')
ct('This is a the first:\lta and the second:\ltb\\ and the third
without extra:\ltc END\\\nThird with extra:\ltcc END\\ 
\vspace{2in}\\ 
All data = zero, frame only:\ltd\\
\end{document}\n')
w <- pngNeedle(c(.2, .5, .7))
cat(tobase64image(w))  # can insert this directly into an html file

## End(Not run)

harrelfe/Hmisc documentation built on Oct. 3, 2019, 9:34 p.m.