2
$\begingroup$

I'm struggling getting a greater than sign (>=) into a forestplot. The expression should embedded in some kind of matrix. This should be simple and straight forward but I just can't find the right formula, here's my debug code:

library(rmeta)
row_names <- matrix(list("variable a", expression(test >= 2)))
test_data <- data.frame(coef=c(1.59, 1.24),
                        low=c(1.3, 0.99),
                        high=c(1.94, 1.55))
forestplot(row_names, test_data$coef, test_data$low, test_data$high, zero = 1)
$\endgroup$
5
  • $\begingroup$ You can't pass an expression inside a matrix. Not sure how to get around this though. $\endgroup$ Commented Aug 16, 2011 at 19:41
  • $\begingroup$ This might be better for StackOverflow, given that this is deeper into R than into statistics, and some of the especially talented R folks may be more likely to see it there than here. $\endgroup$
    – Iterator
    Commented Aug 16, 2011 at 23:47
  • $\begingroup$ Your probably right, my rewrite of the forestplot works well enough for my needs at the moment. I haven't been able to find any good documentation concerning expression objects. I'm also amazed how the R community allows so much uncommented code, this would have been a lot easier if Thomas Lumley had added some comments to the original code (he's far from alone) $\endgroup$
    – Max Gordon
    Commented Aug 17, 2011 at 6:36
  • $\begingroup$ Maybe your update could be posted as an answer? $\endgroup$ Commented Nov 10, 2013 at 18:27
  • $\begingroup$ @AndreSilva: Thank you, I had forgotten about this question. I've written an answer and a blog post, see below. There have been some updates since the previous post and I therefore removed the original code. $\endgroup$
    – Max Gordon
    Commented Dec 8, 2013 at 15:57

1 Answer 1

1
$\begingroup$

I've created a forestplot function that can handle complex labels and other. It is included in my package Gmisc and you can find a tutorial to the forestplot2 function here.

To generate the plot from my original question all you need to do is load the package and run this code:

library(Gmisc)

row_names <- list(list("Variable = 1", expression(Variable >= 2)))
test_data <- data.frame(coef=c(1.59, 1.24),
                        low=c(1.3, 0.74),
                        high=c(1.94, 1.74))
forestplot2(labeltext=row_names, 
            mean=test_data$coef, 
            lower=test_data$low, 
            upper=test_data$high, 
            zero = 1,
            col=fpColors(line="darkblue", box="royalblue"),
            new_page=TRUE)

This gives the following plot:

Forestplot demo

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.