Create Venn-Diagram in R

A Venn diagram (also sometimes also called primary diagram or set diagram) is a diagram that depicts all possible logical relations between a collection of sets. Certain subjects, such as omitted variable bias, can be best be explained by using a Venn diagram. This post shows how to construct a Venn diagram in R.

The following code produces the Venn diagram used in the post explaining the omitted variable bias.

# start with an empty workspace
rm(list = ls())

# load EulerR pkg
library(eulerr)

# create sets
fit <- euler(c(Price = 500, Miles = 500, Age= 500, 
               "Price&Miles" = 200,
               "Price&Age" = 200,
               "Miles&Age" = 200))

png(filename="venn.png")
plot(fit, fill_opacity = 0.3)
dev.off()

The code produces the following Venn diagram:

Advertisements

One thought on “Create Venn-Diagram in R”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.