Color by Significance in R's `forestplot`
The forestplot package doesn’t easily support advanced coloring of each point, specifically to flag significance levels.
It does however supported custom coloring via a moderately complicated custom function, so here’s an example of how to color by significance.
First, create the following function:
local() so that
i isn’t manipulated elsewhere.
clrs object defined in lines 3-4 returns a specific color based upon the
p-value, here stored in
dat$pv. For context, “darkgreen” is used for p-values
below .05, “blue” for p-values below .10 (but above .05), and “darkgrey” for
p-values above .10.
If you want different colors for the points and the lines, define two different
vectors similar to
clrs, and change lines 9-10 to point to the differing
Following the creation of
fn, you can add it to your
Home | Back to blog