knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(Setviz)

Example data

Start with a dataset with logical or binary 0/1 columns:

data[,c("WASH","Protection","Education","Shelter","Livelihoods")] %>% head

Basic Plot

You can create the intersection plot directly:

plot_set_percentages(data = data,
                     varnames = c("WASH","Protection","Education","Shelter","Livelihoods"),
                     nintersects = 12)

Cummulative vs. Exclusive sets

By default, the sets are calcualted cumulatively. This means that in this example in this example, the set "Wash & Shelter" also includes all records that are in "Wash & Shelter & Livelihoods".

To prevent this behaviour and have exact, mutually exclusive sets (meaning that "Wash & Shelter" contains exclusively the records that are TRUE for Wash and shelter and FALSE for all other variables), you can set the mutually_exlusive_sets parameter to TRUE:

plot_set_percentages(data = data,
                             varnames = c("WASH","Protection","Education","Shelter","Livelihoods"),nintersects = 12,
                             mutually_exclusive_sets = TRUE)

Include single category sets

To include sets of a single category (no intersection but only one of the binary data variables are 1/TRUE), set exclude_unique to FALSE.

plot_set_percentages(data = data,
                             varnames = c("WASH","Protection","Education","Shelter","Livelihoods"),nintersects = 12,
                             exclude_unique = FALSE)

As you see above, if you are using cumulative sets, the single-category sets will always be larger than combinations that contain them. This option makes most sense with mutually exclusive sets:

plot_set_percentages(data = data,
                             varnames = c("WASH","Protection","Education","Shelter","Livelihoods"),nintersects = 12,
                             mutually_exclusive_sets = TRUE,
                             exclude_unique = FALSE)

IMPORTANT NOTES



ellieallien/Setviz documentation built on March 8, 2020, 9:58 p.m.