-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from hms-dbmi/master
Merge
- Loading branch information
Showing
2 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Advanced Altair: Multiple Coordinated Views" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 32, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import altair as alt\n", | ||
"import pandas as pd\n", | ||
"import numpy as np" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 34, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div>\n", | ||
"<style scoped>\n", | ||
" .dataframe tbody tr th:only-of-type {\n", | ||
" vertical-align: middle;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe tbody tr th {\n", | ||
" vertical-align: top;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe thead th {\n", | ||
" text-align: right;\n", | ||
" }\n", | ||
"</style>\n", | ||
"<table border=\"1\" class=\"dataframe\">\n", | ||
" <thead>\n", | ||
" <tr style=\"text-align: right;\">\n", | ||
" <th></th>\n", | ||
" <th>week</th>\n", | ||
" <th>continent</th>\n", | ||
" <th>country</th>\n", | ||
" <th>value</th>\n", | ||
" </tr>\n", | ||
" </thead>\n", | ||
" <tbody>\n", | ||
" <tr>\n", | ||
" <th>0</th>\n", | ||
" <td>1</td>\n", | ||
" <td>Asia</td>\n", | ||
" <td>Afghanistan</td>\n", | ||
" <td>5.0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>1</th>\n", | ||
" <td>2</td>\n", | ||
" <td>Asia</td>\n", | ||
" <td>Afghanistan</td>\n", | ||
" <td>13.0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>2</th>\n", | ||
" <td>3</td>\n", | ||
" <td>Asia</td>\n", | ||
" <td>Afghanistan</td>\n", | ||
" <td>4.0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>3</th>\n", | ||
" <td>4</td>\n", | ||
" <td>Asia</td>\n", | ||
" <td>Afghanistan</td>\n", | ||
" <td>0.0</td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>4</th>\n", | ||
" <td>5</td>\n", | ||
" <td>Asia</td>\n", | ||
" <td>Afghanistan</td>\n", | ||
" <td>0.0</td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" week continent country value\n", | ||
"0 1 Asia Afghanistan 5.0\n", | ||
"1 2 Asia Afghanistan 13.0\n", | ||
"2 3 Asia Afghanistan 4.0\n", | ||
"3 4 Asia Afghanistan 0.0\n", | ||
"4 5 Asia Afghanistan 0.0" | ||
] | ||
}, | ||
"execution_count": 34, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"flu = pd.read_csv('flunet2010_11countries.csv', header=[0,1])\n", | ||
"cols = flu.columns.tolist()\n", | ||
"normed = pd.melt(flu, id_vars=[cols[0]], value_vars=cols[1:], var_name=['continent','country'])\n", | ||
"normed = normed.rename(columns={normed.columns[0]: 'week'})\n", | ||
"normed.head()\n", | ||
"\n", | ||
"# setup renderer for Jupyter Notebooks (not needed for Juptyer Lab)\n", | ||
"alt.renderers.enable('notebook')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Visualization 1\n", | ||
"\n", | ||
"#### Create Linked Plots Showing Flu Cases per Country and Total Flu Cases per Week" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Selections:\n", | ||
"* Click to select individual countries.\n", | ||
"* Hold shift and click to select multiple countries.\n", | ||
"* Brush barchart to narrow top view." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Visualization 2\n", | ||
"\n", | ||
"#### Create an Overview+Detail Plot Showing Flu Cases per Country" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Visualization 3\n", | ||
"#### Create Linked Plots Showing Flu Cases per Country per Week and Total Flu Cases per Country\n", | ||
"For this visualization we create two linked plots. One that shows flu cases per country per week and a second on that show the total of all flu cases per country." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |