Back to Blog
Color by Significance in R's `forestplot`
#forestplot #r #visualizationThe 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:


Inside local()
so that i
isn’t manipulated elsewhere.
The clrs
object defined in lines 34 returns a specific color based upon the
pvalue, here stored in dat$pv
. For context, “darkgreen” is used for pvalues
below .05, “blue” for pvalues below .10 (but above .05), and “darkgrey” for
pvalues above .10.
If you want different colors for the points and the lines, define two different
vectors similar to clrs
, and change lines 910 to point to the differing
vectors.
Following the creation of fn
, you can add it to your forestplot()
via:


Back to Blog