Venn Legendary diagram in venneller

I would like to create a legend for the venneller chart. This should be straightforward because the venneuler function returns the colors used for the console. Colors range from 0 to 1. I want to know how to turn these numeric values ​​stored in $ colors into what I can use to fill out the fill argument in the legend.

I tried to do this below using $ colors extracted from venneuler and indexing from colors (). I know this is wrong because the colors () are indexed by the values ​​of the intervals, but they are inserted to show what I need.

set.seed(20) x <- matrix(sample(0:1, 100, replace = TRUE), 10, 10) colnames(x) <- LETTERS[1:10] rownames(x) <- letters[1:10] require(venneuler) y <- venneuler(x) plot(y) y$colors legend(.05, .9, legend = colnames(x), fill = colors()[y$colors]) 
+6
source share
1 answer

Looking at plot.VennDiagram and by default, you can see how it converts numbers in y$colors to rgb color strings. (Try getAnywhere("plot.VennDiagram") to see for yourself.)

Here I put together two bits of code that processed the colors (in your case) into one function that will perform the conversion for you. Perhaps the positioning of the legend could be improved, but this is another problem ...

 col.fn <- function(col, alpha=0.3) { col<- hcl(col * 360, 130, 60) col <- col2rgb(col)/255 col <- rgb(col[1, ], col[2, ], col[3, ], alpha) col } COL <- col.fn(y$colors) # The original order of columns in x is jumbled in the object returned # by venneuler. This code is needed to put the colors and labels back # in the original order (here alphabetical). LABS <- y$labels id <- match(colnames(x), LABS) plot(y) legend(.05, .9, legend = LABS[id], fill = COL[id], x="topleft") 

enter image description here

+8
source

Source: https://habr.com/ru/post/907531/


All Articles