knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(Setviz)
Start with a dataset with logical or binary 0/1 columns:
data[,c("WASH","Protection","Education","Shelter","Livelihoods")] %>% head
You can create the intersection plot directly:
plot_set_percentages(data = data, varnames = c("WASH","Protection","Education","Shelter","Livelihoods"), nintersects = 12)
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)
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)
weight_variable
or the weight_function
paramter. (please see ?plot_set_percentages
for details.)round_to_1_percent
to TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.