{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ac7b95d6",
   "metadata": {
    "id": "ac7b95d6"
   },
   "source": [
    "# Lecture 7 - Plots\n",
    "### Types, How to Make Them, and When to Use Them"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bdce7509",
   "metadata": {
    "id": "bdce7509"
   },
   "source": [
    "#### Goals\n",
    "\n",
    "* Solidify understanding of the six visualization principles introduced last class\n",
    "* Know how to produce, interpret, and choose when to use several of the most commonly used types of data visualizations:\n",
    "    * Tables\n",
    "    * Dot and line plots\n",
    "    * Box and whisker plots\n",
    "    * Scatter plots\n",
    "    * Bar/column plots and (usually not) pie charts\n",
    "    * Histograms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "98b5b2d5",
   "metadata": {
    "executionInfo": {
     "elapsed": 292,
     "status": "ok",
     "timestamp": 1674583742803,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "98b5b2d5"
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9bdbe9da-60a4-46ff-8ad4-3c557ff114c1",
   "metadata": {},
   "source": [
    "### Visualization Principles - Discussion"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "2b6d1b06-b587-4325-8b78-0cb15416f1ab",
   "metadata": {},
   "source": [
    "![](examples/health_income.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ef9c233b-7a69-4e3f-8b99-06de36109080",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "9a724c5a-5071-4a70-9f3d-0e330af990b4",
   "metadata": {},
   "source": [
    "![](examples/ny_weather.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a91bce70-c763-49b0-832a-827aa4d0661f",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "bd6fd184-4b11-4105-bf2a-504b7dcca196",
   "metadata": {},
   "source": [
    "![](examples/crude_price.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "430ea30a-a5e9-41ae-9883-4139e15b3d1d",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "41a051fd-6f12-44d8-9584-8d9b545934c6",
   "metadata": {},
   "source": [
    "![](examples/cotton.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a41fe1f8-60a3-4e51-b6e0-14ef2bf5ffab",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "9b5b10ed-0831-40c8-b215-aa5d845b0ed6",
   "metadata": {},
   "source": [
    "![](examples/unemployment.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8862b92-fbd2-4cb4-a3f1-6641dce3ca23",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "6a2b5d11-615a-4c59-9ba4-82a71980d9b6",
   "metadata": {},
   "source": [
    "![](examples/college_enrollment.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "541682f5-46ba-4217-bbd2-cb6f3306a8b8",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "8b865652-7bdd-4904-ad10-993643acd170",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "43fae0cd-b1ae-47b5-9958-ae2dd0439ee4",
   "metadata": {},
   "source": [
    "### Some Datasets to Play With"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad1ef304-b5b7-4771-8517-0b266ddfb845",
   "metadata": {},
   "outputs": [],
   "source": [
    "penguins = sns.load_dataset(\"penguins\")\n",
    "fmri = sns.load_dataset(\"fmri\")\n",
    "mpg = sns.load_dataset(\"mpg\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff961a21",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 424
    },
    "executionInfo": {
     "elapsed": 209,
     "status": "ok",
     "timestamp": 1674583782921,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "ff961a21",
    "outputId": "d8cb9fac-4f67-415b-e057-06ad1c56cacc"
   },
   "outputs": [],
   "source": [
    "penguins"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c9d58799",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 424
    },
    "executionInfo": {
     "elapsed": 186,
     "status": "ok",
     "timestamp": 1674583818933,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "c9d58799",
    "outputId": "bdd40570-91ea-42ed-947d-a7eb1585ebee"
   },
   "outputs": [],
   "source": [
    "fmri"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c19ffaf-de37-439d-b9f9-d9753bc2f688",
   "metadata": {},
   "outputs": [],
   "source": [
    "fmri.sort_values(by=[\"subject\", \"timepoint\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dcf07c09",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 485
    },
    "executionInfo": {
     "elapsed": 251,
     "status": "ok",
     "timestamp": 1674583885288,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "dcf07c09",
    "outputId": "bd326ad0-3bd6-4747-8474-ca0d2401f3eb"
   },
   "outputs": [],
   "source": [
    "mpg"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9bbb5df2",
   "metadata": {
    "id": "9bbb5df2"
   },
   "source": [
    "## Matplotlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d63fdec",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 297
    },
    "executionInfo": {
     "elapsed": 494,
     "status": "ok",
     "timestamp": 1674584102792,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "0d63fdec",
    "outputId": "5285727b-de3f-4a86-a215-48a27ca24d7e"
   },
   "outputs": [],
   "source": [
    "colors = {\"Adelie\": \"red\", \"Gentoo\": \"green\", \"Chinstrap\": \"blue\"}\n",
    "size = lambda x: 10 if x > 40 else 1\n",
    "plt.scatter(\"body_mass_g\", \"flipper_length_mm\", data=penguins,\n",
    "            c=penguins[\"species\"].map(colors),\n",
    "            s=((penguins[\"bill_depth_mm\"]/4)**2))\n",
    "plt.legend()\n",
    "plt.xlabel(\"Body Mass (g)\")\n",
    "plt.ylabel(\"Flipper Length (mm)\");"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1fe0222d",
   "metadata": {
    "id": "1fe0222d"
   },
   "source": [
    "## Seaborn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ab135876",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 388
    },
    "executionInfo": {
     "elapsed": 809,
     "status": "ok",
     "timestamp": 1674584167977,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "ab135876",
    "outputId": "11f81175-1f8e-4df9-b8d7-9f2c8c164ac2"
   },
   "outputs": [],
   "source": [
    "sns.relplot(x=\"body_mass_g\", y=\"flipper_length_mm\",\n",
    "            hue=\"species\", size=\"bill_depth_mm\", data=penguins)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "58c155bb",
   "metadata": {
    "id": "58c155bb"
   },
   "source": [
    "Key distinction: **figure-level** vs. **axes-level**:\n",
    "https://seaborn.pydata.org/tutorial/function_overview.html\n",
    "![](https://seaborn.pydata.org/_images/function_overview_8_0.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1dcf229a",
   "metadata": {
    "id": "1dcf229a"
   },
   "source": [
    "## Common Data Visualizations"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e970058e",
   "metadata": {
    "id": "e970058e"
   },
   "source": [
    "### Tables\n",
    "\n",
    "Suppose you want to see the 5 biggest penguins."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e64a4523",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 206
    },
    "executionInfo": {
     "elapsed": 212,
     "status": "ok",
     "timestamp": 1674584515462,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "e64a4523",
    "outputId": "971caa05-52f1-43e9-81e8-92410979a9d4"
   },
   "outputs": [],
   "source": [
    "penguins.sort_values(\"body_mass_g\", ascending=False).iloc[:5,:]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac4095cf",
   "metadata": {
    "id": "ac4095cf"
   },
   "source": [
    "Table Tips:\n",
    "* Think about row and column ordering\n",
    "* Label columns and rows well (clear but concise).\n",
    "* Uniform precision, right-justified numbers.\n",
    "* Sometimes: bold or emphasize max or min values in a column"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0dca8da2",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 206
    },
    "executionInfo": {
     "elapsed": 229,
     "status": "ok",
     "timestamp": 1674584667242,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "0dca8da2",
    "outputId": "1d7c7759-7fe3-40b2-d210-359e641a9c2c"
   },
   "outputs": [],
   "source": [
    "p = penguins.rename(columns={\"species\": \"Species\", \"island\": \"Island\",\n",
    "                 \"bill_length_mm\": \"Bill Length (mm)\",\"bill_depth_mm\": \"Bill Depth (mm)\",\n",
    "                 \"flipper_length_mm\": \"Flipper Length (mm)\", \"body_mass_g\": \"Body Mass (g)\",\n",
    "                 \"sex\": \"Sex\"})\n",
    "p = p[[\"Species\", \"Island\", \"Sex\", \"Body Mass (g)\", \"Bill Length (mm)\", \"Bill Depth (mm)\", \"Flipper Length (mm)\"]]\n",
    "p.sort_values(\"Body Mass (g)\", ascending=False).iloc[:5,:]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "45085e2b",
   "metadata": {
    "id": "45085e2b"
   },
   "source": [
    "### Dot plots, Line Plots\n",
    "\n",
    "Conceptually (but not technically) different from a scatter plot, in that $x$ values are assumed to be ordered."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b265cfec-9ddb-4349-9c2d-7a689dcaafed",
   "metadata": {},
   "outputs": [],
   "source": [
    "mpg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "489ff9da",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 489
    },
    "executionInfo": {
     "elapsed": 238,
     "status": "ok",
     "timestamp": 1674584705230,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "489ff9da",
    "outputId": "4ebead78-1f21-43ea-c267-bc571ca17f53"
   },
   "outputs": [],
   "source": [
    "mpg_year = mpg.groupby(\"model_year\")[[\"mpg\"]].mean()\n",
    "mpg_year"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a55a99f3",
   "metadata": {
    "id": "a55a99f3"
   },
   "source": [
    "No connected dots - technically the same as a scatter plot."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "425a17a0",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 388
    },
    "executionInfo": {
     "elapsed": 479,
     "status": "ok",
     "timestamp": 1674584727779,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "425a17a0",
    "outputId": "151c7953-c01b-4a26-de86-61e55dfe11ff"
   },
   "outputs": [],
   "source": [
    "sns.relplot(x=\"model_year\", y=\"mpg\", kind=\"scatter\", data=mpg_year)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ffa5e38a",
   "metadata": {
    "id": "ffa5e38a"
   },
   "source": [
    "Connect the dots: now you have a line plot:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01b39c91",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 388
    },
    "executionInfo": {
     "elapsed": 630,
     "status": "ok",
     "timestamp": 1674584773170,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "01b39c91",
    "outputId": "7a0f9cd7-6cbf-425f-b974-21df46ef50b4"
   },
   "outputs": [],
   "source": [
    "sns.relplot(x=\"model_year\", y=\"mpg\", kind=\"line\", data=mpg_year)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "229b40c6",
   "metadata": {
    "id": "229b40c6"
   },
   "source": [
    "Seaborn does sensible things if you have multiple datapoints per $x$ value:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "719ad595",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 388
    },
    "executionInfo": {
     "elapsed": 826,
     "status": "ok",
     "timestamp": 1674585084403,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "719ad595",
    "outputId": "db57dcc0-bfc1-4a79-a65f-30260c56cb69"
   },
   "outputs": [],
   "source": [
    "sns.relplot(x=\"model_year\", y=\"mpg\", kind=\"line\", data=mpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f4f671e",
   "metadata": {
    "id": "2f4f671e"
   },
   "source": [
    "**Exercise**: when should you connect the dots?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "32eef61c",
   "metadata": {
    "id": "32eef61c"
   },
   "source": [
    "### Box and whisker plots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8caa9de0",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 297
    },
    "executionInfo": {
     "elapsed": 531,
     "status": "ok",
     "timestamp": 1674585151222,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "8caa9de0",
    "outputId": "50520312-6af8-4ef1-b793-852219e3cf9b"
   },
   "outputs": [],
   "source": [
    "sns.boxplot(x=\"species\", y=\"body_mass_g\", data=penguins)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6583ee28",
   "metadata": {
    "id": "6583ee28"
   },
   "source": [
    "**Exercise**: Of the ones we've discussed so far (table, dot/line, box and whisker), which kind of visualization would you use to illustrate each of the following?\n",
    "1. The number of cars per model year in the MPG dataset\n",
    "2. The distribution of each penguin body measurement, independent of species.\n",
    "3. The centrality and variability of each penguin body measurement per species.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3e7dbf0",
   "metadata": {
    "id": "c3e7dbf0"
   },
   "source": [
    "### Scatter plots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "46555b63",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 388
    },
    "executionInfo": {
     "elapsed": 863,
     "status": "ok",
     "timestamp": 1674585788631,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "46555b63",
    "outputId": "b5b03c32-9b0a-4cfa-d44b-5633a672c377"
   },
   "outputs": [],
   "source": [
    "sns.relplot(data=penguins, x=\"flipper_length_mm\", y=\"bill_length_mm\", hue=\"species\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "179d112f",
   "metadata": {
    "id": "179d112f"
   },
   "source": [
    "### Bar/column plots and (usually not) pie charts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4700ee06",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 387
    },
    "executionInfo": {
     "elapsed": 467,
     "status": "ok",
     "timestamp": 1674585859392,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "4700ee06",
    "outputId": "8ed54c81-2205-45b0-813f-37f55901abdc"
   },
   "outputs": [],
   "source": [
    "sns.catplot(x=\"species\", data=penguins, kind=\"count\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c9df71e",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 317
    },
    "executionInfo": {
     "elapsed": 801,
     "status": "ok",
     "timestamp": 1674585893567,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "4c9df71e",
    "outputId": "3e9798d5-e882-4351-d7f1-ad42e9b1e650"
   },
   "outputs": [],
   "source": [
    "sns.catplot(x=\"species\", data=penguins, kind=\"count\", col=\"island\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a8934176",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 387
    },
    "executionInfo": {
     "elapsed": 406,
     "status": "ok",
     "timestamp": 1674585947169,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "a8934176",
    "outputId": "f73372e7-9c32-4f1a-8352-cf788512160d"
   },
   "outputs": [],
   "source": [
    "sns.catplot(x=\"species\", data=penguins, kind=\"count\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27df9283",
   "metadata": {
    "id": "27df9283"
   },
   "source": [
    "### Histograms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "acac8e4e",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 387
    },
    "executionInfo": {
     "elapsed": 407,
     "status": "ok",
     "timestamp": 1674585971683,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "acac8e4e",
    "outputId": "39fc6b44-972b-41c4-d4bc-35e5883046c5"
   },
   "outputs": [],
   "source": [
    "sns.displot(penguins, x=\"flipper_length_mm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "328516e1",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 387
    },
    "executionInfo": {
     "elapsed": 531,
     "status": "ok",
     "timestamp": 1674586091217,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "328516e1",
    "outputId": "71c6ac06-593d-490d-8eb6-bf61d10137f1"
   },
   "outputs": [],
   "source": [
    "sns.displot(penguins, x=\"flipper_length_mm\", stat='density')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99ba4b55",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 317
    },
    "executionInfo": {
     "elapsed": 1184,
     "status": "ok",
     "timestamp": 1674586111632,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "99ba4b55",
    "outputId": "ac7c3709-2401-4900-bfe2-711ad98aaf67"
   },
   "outputs": [],
   "source": [
    "sns.displot(penguins, x=\"flipper_length_mm\", col='species')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e4646f3",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 387
    },
    "executionInfo": {
     "elapsed": 870,
     "status": "ok",
     "timestamp": 1674586147661,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "9e4646f3",
    "outputId": "f397ee15-f3ac-4456-dffd-bf56ff289cb3"
   },
   "outputs": [],
   "source": [
    "sns.displot(penguins, x=\"flipper_length_mm\", hue=\"species\", stat=\"density\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ed30808a",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 295
    },
    "executionInfo": {
     "elapsed": 1370,
     "status": "ok",
     "timestamp": 1674586171953,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "ed30808a",
    "outputId": "db680331-bc56-4a0b-b33e-05b6ba16d555"
   },
   "outputs": [],
   "source": [
    "sns.displot(penguins, x=\"flipper_length_mm\", hue=\"species\", col=\"island\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cd41066b",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 295
    },
    "executionInfo": {
     "elapsed": 1524,
     "status": "ok",
     "timestamp": 1674586187113,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "cd41066b",
    "outputId": "d251a8b9-6e63-4268-8e20-b5759aada226"
   },
   "outputs": [],
   "source": [
    "sns.displot(penguins, x=\"flipper_length_mm\", hue=\"species\", col=\"island\", kde='True')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb8bb8e4",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 459
    },
    "executionInfo": {
     "elapsed": 1135,
     "status": "ok",
     "timestamp": 1674586197341,
     "user": {
      "displayName": "Scott Wehrwein",
      "userId": "11327482518794216604"
     },
     "user_tz": 480
    },
    "id": "fb8bb8e4",
    "outputId": "eb1e05c9-3a2d-46b4-aa5c-b2f771c33c7a"
   },
   "outputs": [],
   "source": [
    "sns.jointplot(x=\"bill_length_mm\", y=\"bill_depth_mm\", data=penguins, kind='hex')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "XSEw45tooWdA",
   "metadata": {
    "id": "XSEw45tooWdA"
   },
   "outputs": [],
   "source": [
    "fmri[fmri[\"subject\"]==\"s0\"].sort_values(by=\"timepoint\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4n2jFbHon7pv",
   "metadata": {
    "id": "4n2jFbHon7pv"
   },
   "source": [
    "**Exercise:** Of the ones we've discussed so far (table, dot/line, box and whisker), which kind of visualization would you use to illustrate each of the following?\n",
    "1. Average signal per subject in the fmri dataset.\n",
    "2. The signal over time for each event type in patient 0, regardless of region.\n",
    "3. The distribution of bill lengths for Adelie penguins."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c2611bfa",
   "metadata": {
    "id": "c2611bfa"
   },
   "source": [
    "A helpful figure from the book:\n",
    "![](https://facultyweb.cs.wwu.edu/~wehrwes/courses/data311_23w/lectures/L07/vis_decisiontree.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d6e78d6-1fcf-4296-843e-192582cfe97e",
   "metadata": {},
   "source": [
    "**Additional Practice**: Download `L06_exit.ipynb` and add code to make one or more plots visualizing the response data."
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
