Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force the labels to fit in VennDiagram?

Tags:

r

venn-diagram

I use VennDiagram to make a venn diagram with the following example code:

library(VennDiagram)
venn.diagram(list(shams_90d = 1:3, shams_90d_4h = 2:4, sham3__shams_90d = 3:5,
             sham3_90d__shams = 5:7, sham3_90d__shams_4h = 6:9),
             fill = c("red", "green", "blue", "yellow", "purple"),
             alpha = c(0.5, 0.5,0.5, 0.5, 0.5), cex = 1,cat.fontface = 2,
             lty =1, filename = "trial2.emf");

Which gives this figure:

enter image description here

The names on the left and right of the figure are cut off, and a little bit of the name at the bottom as well. I tried changing width, but that makes the venn diagram itself get wider, and the names still get cut off.

How can I make the VennDiagram so that it includes the full names, either by adding more whitespace on the left and right of the diagram, or by pushing the names more towards the venn diagram?

like image 787
Niek de Klein Avatar asked Jan 20 '14 12:01

Niek de Klein


1 Answers

You can justify the label text with cat.just. The package reference manual gives info. on how to pass the parameters.

For your example i used trial and error for the justification values.

# Plot
v <- venn.diagram(list(shams_90d = 1:3, shams_90d_4h = 2:4, sham3__shams_90d = 3:5,
                   sham3_90d__shams = 5:7, sham3_90d__shams_4h = 6:9),
              fill = c("red", "green", "blue", "yellow", "purple"),
              alpha = c(0.5, 0.5,0.5, 0.5, 0.5), cex = 1,cat.fontface = 2,
              lty =1, filename=NULL, cat.cex=0.8, 
              cat.just=list(c(0.6,1) , c(0,0) , c(0,0) , c(1,1) , c(1,0)))

grid.newpage()
grid.draw(v)

enter image description here

Another option (if a bit of a quick hack) would be to remove the cat.just argument and set a smaller grid::viewport. You may need to tweak the width of your graphics window / output device (ie pdf(..., width=...)):

# Plot
v <- venn.diagram(list(shams_90d = 1:3, shams_90d_4h = 2:4, sham3__shams_90d = 3:5,
                   sham3_90d__shams = 5:7, sham3_90d__shams_4h = 6:9),
              fill = c("red", "green", "blue", "yellow", "purple"),
              alpha = c(0.5, 0.5,0.5, 0.5, 0.5), cex = 1,cat.fontface = 2,
              lty =1, filename=NULL, cat.cex=0.8)

grid.newpage()
pushViewport(viewport(width=unit(0.8, "npc"), height = unit(0.8, "npc")))
grid.draw(v)

enter image description here

like image 168
user20650 Avatar answered Sep 23 '22 21:09

user20650