Skip to content

Venn diagram using nVennR package

This is an example of a Venn diagram using R package {nVennR}. Number of COPD cases was compared between competing definitions.

### Not to run ###

library(nVennR)
library(rsvg)

# compare the number of COPD cases based on GOLD definition
cases <- list(All = d$pid, 
              PreSpirometry = d$pid[d$copd_gold_all_s3 == 1],
              PostSpirometry = d$pid[d$COPDdil_gold_all_s3 == 1],
              Asthma = d$pid[d$docast_s3 == 1])
venn.cpgs <- plotVenn(cases, nCycles = 10000,
                      outFile = 'results/venn_diagram_COPD_GOLD.svg')
venn2.cpgs <- plotVenn(nVennObj = venn.cpgs, nCycles = 10000,
                       outFile = 'results/venn_diagram_COPD_GOLD.svg')
showSVG(nVennObj = venn2.cpgs, opacity = 0.1, borderWidth = 2, labelRegions = F,
        outFile = 'results/venn_diagram_COPD_GOLD.svg')
svg.cpg <- rsvg('results/venn_diagram_COPD_GOLD.svg', height = 3000)
jpeg::writeJPEG(svg.cpg, 'results/venn_diagram_COPD_GOLD.jpg')