How to force the labels to fit in VennDiagram?

廉价感情. 提交于 2019-12-05 17:49:19

问题


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:

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?


回答1:


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)

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)



来源:https://stackoverflow.com/questions/21234439/how-to-force-the-labels-to-fit-in-venndiagram

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!