Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have title in R Vennerable Venn Diagram?

Tags:

r

venn-diagram

I cannot find anything in documentation here. Code

library("Vennerable")
data(StemCell)
Vstem <- Venn(StemCell)
Vstem3 <- Vstem[, c("OCT4", "SOX2", "NANOG")]
tl <- "masi"
plot(Vstem3, doWeights = TRUE, type = "circles")

Tried unsuccessfully

  • plot(..., main = tl)
  • plot(..., title = tl)
  • plot(...); title(tl)
  • plt <- plot(...); title(plt, tl)

Fig. 1 Wrong output without title

enter image description here

R: 3.3.1
OS: Debian 8.5

like image 605
Léo Léopold Hertz 준영 Avatar asked Nov 14 '16 20:11

Léo Léopold Hertz 준영


People also ask

What is the crossover in a Venn diagram called?

The region included in both A and B, where the two sets overlap, is called the intersection of A and B, denoted by A ∩ B.

What do you call the parts of a Venn diagram?

While there are many ways to organize a Venn diagram, they most often consist of overlapping circles. Each circle by itself represents a set, which may include ideas, concepts, numbers, or objects. When circles overlap or intersect, those sub-sets that are shared are known as a union or intersection.


1 Answers

user20650 answer in comments summarised here. Try (1-2) and choose what fits best.

  1. The plot method is based on the grid package so the normal base R plot approaches to add a title won't work. Looking at the arguments of args(Vennerable:::plotVenn), there doesn't seem a way to add a title and unhelpfully the plots do not return a grid object. So you can just draw a title on the plot window with the following

    grid.text("masi", y=0.9, gp=gpar(col="red", cex=2))
    
  2. As an alternative method, you could grab the grob and then use grid.arrange to plot the title

    gridExtra::grid.arrange(grid::grid.grabExpr(plot(Vstem3, doWeights = TRUE, 
       type = "circles")), top="masi")
    

The grid.arrange way adds the title as a separate grob, and then they are arranged in two rows. So when resizing the graphics window, it still appears above the plot. This won't be true when drawing straight on the window (as in the first version). Note: you do not need to use gridExtra, you could do this in grid.

Fig. 1 Output from (1), Fig. 2 Output from (2)

enter image description here enter image description here

I think (1) could be better with more adjustments, but now (2) is better.

like image 171
2 revs Avatar answered Nov 10 '22 08:11

2 revs