Generic plots

Generic plots#

This notebook shows how to use the polyflame library to generate plots for clinical data. In practice you will use the data format specific libraries to produce the data that will be plotted, such as from the FHIRflat or REDCap formats.

For all data types, the generic plot() function can be used to plot, with a plot type parameter.

import pandas as pd
from polyflame.plots import plot_unpacked

Proportion plots#

Proportion plots show the relative proportion frequency of a column. Usually used to show prevalence of clinical conditions

prop_data = pd.DataFrame({"condition": ["cough", "sore throat", "fever"], "values": [0.7, 0.6, 0.3]})
prop_data
condition values
0 cough 0.7
1 sore throat 0.6
2 fever 0.3
plot_unpacked(prop_data, "proportion", cols={"label": "condition", "proportion": "values"})

UpSet plots#

UpSet plots are used to show sets and the relative frequency of intersections. Thus for a three-element set, there will be 2^3^ = 8 intersections. Intersections are displayed through connected dots.

upset_data = pd.DataFrame({"headache": [0, 1, 1], "cough": [1, 0, 1], "sore throat": [0, 0, 1]})
upset_data
headache cough sore throat
0 0 1 0
1 1 0 0
2 1 1 1
plot_unpacked(upset_data, "upset")