0

I am trying to show a ggforest plot, the plot gets rendered perfectly in r-studio but it does not show up in r-notebook.

Here is a reproducible example.

library(ggplot2)
library(survival)
library(survminer)

data("veteran")
cox = coxph(Surv(time, status) ~ karno+celltype, data = veteran)
ggforest(cox, data = veteran)

When I run the above code, it creates a plot in R-studio (r-script), but does not create any plot in r-notebook

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Edit: I looked at the definition of ggforest and the last statement of that function is invisible(p) where p is a ggplot object. Could that be somehow related to graph not showing up in the notebook. I also tried to write the same function without invisible(p) but ran into errors as it could not find certain functions like .get_data() and tidy().

Gaurav Singhal
  • 998
  • 2
  • 10
  • 25
  • 1
    Does it work if you assign the plot a name and then `print()` it? – aosmith Jul 05 '18 at 22:45
  • @aosmith, thanks, it works, but it plots the same graph twice. How do I get rid of second graph. I tried `p = ggforest(cox, data = veteran); p` , `p = ggforest(cox, data = veteran); print(p)`, `p = ggforest(cox, data = veteran); plot(p)`. All of these plot the graph twice. – Gaurav Singhal Jul 06 '18 at 11:45
  • Well, I got a workaround, thanks to your idea. I assigned the plot name in one chunk and called that in next code chunk. Now it plots only once. – Gaurav Singhal Jul 06 '18 at 13:32
  • Glad you found a work-around but definitely seems odd. I was also seeing double plots when I would run the whole chunk but not when I ran the code directly. – aosmith Jul 06 '18 at 13:35
  • @aosmith, were you able to reproduce the actual issue. I opened a issue on github but concerned person is not able to reproduce the issue. It will be beneficial for everyone you could tell if you face the same issue on your machine. – Gaurav Singhal Jul 09 '18 at 05:02
  • 1
    Yes, if I put your code into a chunk in a Notebook and run the chunk then the plot does not appear in the Rmd file or output. If I then add `print()` I get two plots when I run the chunk. I'm on Windows 7 with R 3.5.1 and RStudio 1.1.453. – aosmith Jul 09 '18 at 13:11

0 Answers0