简体   繁体   中英

Adding extra texts to a venn diagram drawn using VennDiagram R package

I have a code taken from the package VennDiagram for drawing a venn diagram (below). I'm able to implement this code to draw a venn diagram, but I would also like to add extra text to each of the partitioned areas (unique and common to I, II, II, IV). For example, after running this code, the unique section 'I' is 60, I will like to add something like XX XU at the bottom of 60, and so on for the other partitioned areas as well. Is there a way in R to modify this code to achieve these changes?

library(VennDiagram)

venn.plot <- venn.diagram(
   x = list(
       I = c(1:60, 61:105, 106:140, 141:160, 166:175, 176:180, 181:205, 206:220),
       IV = c(531:605, 476:530, 336:375, 376:405, 181:205, 206:220, 166:175, 176:180),
       II = c(61:105, 106:140, 181:205, 206:220, 221:285, 286:335, 336:375, 376:405),
       III = c(406:475, 286:335, 106:140, 141:160, 166:175, 181:205, 336:375, 476:530)
       ),
filename = "1D-quadruple_Venn.tiff",
col = "black",
lty = "dotted",
lwd = 4,
fill = c("cornflowerblue", "green", "yellow", "darkorchid1"),
alpha = 0.50,
label.col = c("orange", "white", "darkorchid4", "white", "white", "white",
 "white", "white", "darkblue", "white",
  "white", "white", "white", "darkgreen", "white"),
cex = 2.5,
fontfamily = "serif",
fontface = "bold",
cat.col = c("darkblue", "darkgreen", "orange", "darkorchid4"),
cat.cex = 2.5,
cat.fontfamily = "serif"
);

venn digrams:

在此处输入图片说明

Thanks

Something to help you start:

I used your example, but for filename I used NULL , because I wanted to plot the venn diagram along with extra labels.

## Function that creates a grid.text object
## The offset sets the distance from existing label 
addlab <- function(lab, x, y, offset = 0) {
    grid.text(lab, unit(as.numeric(x), "npc"), 
                   unit(as.numeric(y) - offset, "npc"), 
              draw = FALSE)
}

## Adding a number under each label
lbls <- gList()
o <- 1 ## counter
for(i in seq(along.with=venn.plot)) {
  ## Check if it is a grid.text object
  if(regexpr("text", venn.plot[[i]]$name) > 0) {
    ## Write counter value under the existing label
    lbls <- gList(lbls, addlab(o, venn.plot[[i]]$x, venn.plot[[i]]$y, 0.03))
    ## Increase the counter
    o <- o + 1
  }
}

Plot the Venn diagram and the labels:

## tiff("out.tiff")
grid.draw(venn.plot)
grid.draw(lbls)
## dev.off()

在此处输入图片说明

From the numbers you can see the order you have to put your labels to achieve what you want.

Hope this will help you,

alex

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM