When producing numbers in R markdown documents, it can be nice to try and
draw readers' attention to increases and decreases. The
function takes a numeric vector, and returns a
vector of HTML strings, which will render in an (R) markdown document as
numbers accompanied with a green 'upward' triangle for positive numbers, a
red 'downward' triangle for negative ones, and a black square for numbers
which are exactly 0 by default. The colours can be altered by passing valid
CSS colour values to the
colours argument, and the symbols by
passing valid HTML character values to the
symbols argument. The
default values are in HTML decimal character codes.
If you'd only like to green/red triangles for some non-zero numbers, you
can use the subset argument to pass a
logical vector (the
same) length as
html_tri. This will mean that only
x will get a traingle when they are non-negative
1 2 3
A function used to format the numbers before the HTML for the triangles is added.
The symbols to use for increases, decreases, and things
not chaning respectively. Must a a vector of length 3, the entries having
As above, but for the colours of the symbols
A vector of
character values, containing HTML so that
they should render with green/red triangles in an HTML document.
Brendan Rocks [email protected]
1 2 3 4 5 6 7 8 9 10 11
# This will output 'raw' HTML. To see the final result in an HTML markdown # document, see the package vignette; vignette("brocks") html_tri(runif(10)) # You could use other HTML symbols, even emojis if you like! # These are HTML decimal codes (only unicode allowed in R packages), but # you could use any valid characters (e.g. copy and paste) html_tri(runif(10), symbols = c("up" = "😊", "down" = "😞", "nochange" = "😐"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.