{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "9d84a71acf5a07adb9451c3fbf2be632",
"grade": false,
"grade_id": "cell-d7dff6881e80c256",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"# Worksheet 4: Effective Data Visualization \n",
"\n",
"\n",
"### Lecture and Tutorial Learning Goals:\n",
"\n",
"Expand your data visualization knowledge and tool set beyond what we have seen and practiced so far. We will move beyond scatter plots and learn other effective ways to visualize data, as well as some general rules of thumb to follow when creating visualizations. All visualization tasks this week will be applied to real world data sets.\n",
"\n",
"\n",
"After completing this week's lecture and tutorial work, you will be able to:\n",
"\n",
"- Describe when to use the following kinds of visualizations:\n",
" - scatter plots\n",
" - line plots\n",
" - bar plots\n",
" - histogram plots\n",
"- Given a dataset and a question, select from the above plot types to create a visualization that best answers the question\n",
"- Given a visualization and a question, evaluate the effectiveness of the visualization and suggest improvements to better answer the question\n",
"- Identify rules of thumb for creating effective visualizations\n",
"- Define the three key aspects of ggplot objects:\n",
" - aesthetic mappings\n",
" - geometric objects\n",
" - scales\n",
"- Use the `ggplot2` library in R to create and refine the above visualizations using:\n",
" - geometric objects: `geom_point`, `geom_line`, `geom_histogram`, `geom_bar`, `geom_vline`, `geom_hline`\n",
" - scales: `scale_x_continuous`, `scale_y_continuous`\n",
" - aesthetic mappings: `x`, `y`, `fill`, `colour`, `shape`\n",
" - labelling: `xlab`, `ylab`, `labs`\n",
" - font control and legend positioning: `theme`\n",
" - subplots: `facet_grid`\n",
"- Describe the difference in raster and vector output formats\n",
"- Use `ggsave` to save visualizations in `.png` and `.svg` format\n",
"\n",
"This worksheet covers parts of [the Visualization chapter](https://datasciencebook.ca/viz.html) of the online textbook. You should read this chapter before attempting the worksheet."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "237242936ecd90fd317dd2d633dd06c5",
"grade": false,
"grade_id": "cell-1fdb1939e17b5421",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"### Run this cell before continuing. \n",
"library(tidyverse)\n",
"library(repr)\n",
"options(repr.matrix.max.rows = 6)\n",
"source(\"tests.R\")\n",
"source(\"cleanup.R\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "c89a5273f3aee1db6c4e31643fcb7d29",
"grade": false,
"grade_id": "cell-3c378af00356c0f3",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 0.1** True or False: \n",
"
{points: 1}\n",
"\n",
"For each of the items below, which are aesthetics in `ggplot2`? \n",
"\n",
"A. `colour`
\n",
"B. `scale`
\n",
"C. `x`
\n",
"D. `fill`
\n",
"E. `type`\n",
"\n",
"*Assign either \"true\" or \"false\" for each to an object called `answer0.1_L` where `L` should be replaced by the letter corresponding to the question. For example, if above we had F. `shape`, we would set `answer0.1_F <- \"true\"`.*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "47b588aa8da4dc077b9f20c8af72e9d2",
"grade": false,
"grade_id": "cell-d42b5b5cadd02544",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# Replace the fail() with your answer. \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "ec191e930f7c437b0debdebc9854d083",
"grade": true,
"grade_id": "cell-65573b490f8813ec",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_0.1()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "f97fa5d01dc4e60bb2920829edfda9b6",
"grade": false,
"grade_id": "cell-a7dfc6e8e27d0615",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 0.2** Multiple Choice:\n",
"
{points: 1}\n",
"\n",
"When deciding on the size of your visualization we recommend that you: \n",
"\n",
"A. Only make the plot area (where the dots, lines, bars are) as big as needed\n",
"\n",
"B. Make it as big as your screen allows\n",
"\n",
"C. Use the default given by `ggplot`\n",
"\n",
"*Assign your answer to an object called `answer0.2`. Make sure your answer is an uppercase letter and is surrounded by quotation marks (e.g. `\"F\"`).*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "c102fe1412b1b6c18e9d7beda83d20a2",
"grade": false,
"grade_id": "cell-46cbbfc18df2f1a2",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# Replace the fail() with your answer. \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "8eb5c7836126d1fd2d396d4b08a465ab",
"grade": true,
"grade_id": "cell-165bb2f307f14e34",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_0.2()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "f908be3d8f9e0a327b0b4a02d43cc447",
"grade": false,
"grade_id": "cell-a64e6788a027a69c",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 0.3** Multiple Choice:\n",
"
{points: 1}\n",
"\n",
"Under what circumstance would you use a static (non-interactive) 3D plot??\n",
"\n",
"A. Anytime you have more than two variables that you want to show the relationship between\n",
"\n",
"B. When you want to emphasize the large difference between groups\n",
"\n",
"C. When you need to grab attention of your audience\n",
"\n",
"D. Rarely, we generally avoid 3D plots because they are often harder to interpret than 2D plots\n",
"\n",
"*Assign your answer to an object called `answer0.3`. Make sure your answer is an uppercase letter and is surrounded by quotation marks (e.g. `\"F\"`).*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "d3088ea2521fd5c2677ebbac7253e231",
"grade": false,
"grade_id": "cell-e3a98de134b6b2f0",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# Replace the fail() with your answer. \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "f9c81ef0442bbff11200f38cb521eaa4",
"grade": true,
"grade_id": "cell-521dc123937db46d",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_0.3()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "ddc4e2c6fb1327d5ead0fdaef08d69c9",
"grade": false,
"grade_id": "cell-7148c0706bcb2d4b",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 0.4** Multiple Choice:\n",
"
{points: 1}\n",
"\n",
"What is the symbol used to add a new layer to a `ggplot` object?\n",
"\n",
"A. `<-`\n",
"\n",
"B. `|>`\n",
"\n",
"C. `%&%`\n",
"\n",
"D. `+`\n",
"\n",
"*Assign your answer to an object called `answer0.4`. Make sure your answer is an uppercase letter and is surrounded by quotation marks (e.g. `\"F\"`).*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "4fc162b57d921bcc81af77f53001c23c",
"grade": false,
"grade_id": "cell-ea7ba4f1243e667d",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# Replace the fail() with your answer. \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "e13370e0ecbd45a11ee6413cb4ab5fe7",
"grade": true,
"grade_id": "cell-5c15ea7ab4b4655e",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_0.4()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "5bf8bd2edd9dc01e95953e4531fe278a",
"grade": false,
"grade_id": "cell-d33780730eef352c",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"**Question 0.5** Item Arrangement\n",
"
{points: 1}\n",
"\n",
"Match the following geometric objects to their corresponding visualization purposes.\n",
"\n",
"1. `geom_histogram`\n",
"2. `geom_hline`\n",
"3. `geom_point`\n",
"4. `geom_line`\n",
"5. `geom_vline`\n",
"6. `geom_bar`\n",
"\n",
"A. Visualizing the distribution of data in one dimension
\n",
"B. Visualizing the relationship between two variables in two dimensions
\n",
"C. Comparing amounts
\n",
"D. Drawing a straight, vertical line at a specified position on the x-axis.
\n",
"E. Drawing a straight, horizontal line at a specified position on the y-axis.
\n",
"F. Showing a trend with respect to an independent quantity
\n",
"\n",
"*Assign each single character answer (e.g. \"D\") to an object called `answer0.5_#` where `#` should be \n",
"replaced by the number corresponding to the item. For example, if we wanted to match 1 to F above, we would\n",
"set `answer0.5_1 <- \"F\"`.*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "520864a08e62ae114da6e8af52e39cb0",
"grade": false,
"grade_id": "cell-3f32a93753a230e1",
"locked": false,
"schema_version": 3,
"solution": true,
"task": false
}
},
"outputs": [],
"source": [
"# Replace the fail() with your answer. \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "4472725532a68531d24de8ef5c05b3b3",
"grade": true,
"grade_id": "cell-7b95a04e22cfd223",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"test_0.5()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "5f66540df0550f6bce458b3273d5d302",
"grade": false,
"grade_id": "cell-603e82af426c3ceb",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"## 1. World Vaccination Trends\n",
"\n",
"Data scientists find work in all sectors of the economy and all types of organizations. Some work in collaboration with public sector organizations to solve problems that affect society, both at local and global scales. Today we will be looking at a global problem with real data from the [World Health Organization](https://www.who.int/) (WHO). According to WHO, Polio is a disease that affects mostly children younger than 5 years old, and to date there is no cure. However, when given a vaccine, children can develop sufficient antibodies in their system to be immune to the disease. Another disease, Hepatitis B, is also known to affect infants but in a chronic manner. There is also a vaccine for Hepatitis B available. \n",
"\n",
"The columns in the dataset are:\n",
"\n",
"- `who_region` - The WHO region of the world\n",
"- `yr` - The year\n",
"- `pct_vaccinated` - Estimated percentage of people vaccinated in the region\n",
"- `vaccine` - Whether it's the `polio` or the `hepatitis_b` vaccine\n",
"\n",
"We want to know two things. First, has there been a change in Polio or Hepatitis B vaccination patterns throughout the years? And if so, what is that pattern? Second, have the vaccination patterns for one of these diseases changed more than the other? **The goal for today is to produce a plot of the estimated percentage of people vaccinated per year**. To do this, you will follow the steps outlined below.\n",
"\n",
"The original datasets are available here:\n",
" - Polio: http://apps.who.int/gho/data/view.main.81605?lang=en\n",
" - Hepatitis B: http://apps.who.int/gho/data/view.main.81300?lang=en\n",
" \n",
"The data set we will work with for this worksheet however is named `world_vaccination.csv` and it lives in the `worksheet_04/data` directory."
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "b2866ded6705058c9b4a546fc2f3fb6b",
"grade": false,
"grade_id": "cell-6767e740b3c9df90",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 1.0** Multiple Choice:\n",
"
{points: 1}\n",
"\n",
"Consider the variables `yr` and `pct_vaccinated`. These variables are:\n",
"\n",
"A. both quantitative (e.g., numerical).\n",
"\n",
"B. both categorical\n",
"\n",
"C. one is categorical and one is quantitative\n",
"\n",
"D. None of the above. \n",
"\n",
"*Assign your answer to an object called `answer1.0`. Make sure your answer is an uppercase letter and is surrounded by quotation marks (e.g. `\"F\"`).*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "1519085ad9f2add3a2e67c34250f7cb4",
"grade": false,
"grade_id": "cell-eeda947331564185",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# Replace the fail() with your answer. \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "1bc7013cddd6a3e4d711baa8532a93f8",
"grade": true,
"grade_id": "cell-abc8ab4c34c2959d",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_1.0()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "f58bda672bc930d398957e9107798713",
"grade": false,
"grade_id": "cell-cfc4be1132bff6c2",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"**Question 1.1** \n",
"
{points: 1}\n",
"\n",
"Read the `world_vaccination.csv` file. Filter the data so that we don't have any NA's in the `pct_vaccinated` column. We also want to filter out (i.e., remove) the `(WHO) Global` region as it is just the average of the other regions. Assign the remaining data (without the `(WHO) Global` region) to an object called `world_vaccination`.\n",
"\n",
"Hint: When you want to filter for rows that aren't equal to something, in R you can use the `!=` operator. For example, to remove all the cars with 6 cylinders from the `mtcars` built-in R data set we would do the following:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "47df0ce610d372b35f6298f7481fb705",
"grade": false,
"grade_id": "cell-7b703d29bb313b9a",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"filter(mtcars, cyl != 6) "
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "f8d45f89d2842f02c4e477172b0ad1ff",
"grade": false,
"grade_id": "cell-1c00eadb82617fcb",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"The function `is.na()` is a function that indicates which elements are missing. Since the `!=` operator filters rows that are *not equal* to something, we can use `!is.na()` to find the values that are *not equal to NA*. For instance, to filter out NAs from the `cyl` column in the `mtcars` data set we would do the following: "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "e5fd435b56b3976e1dfed50c27a8dca9",
"grade": false,
"grade_id": "cell-c41429b8aa8218cc",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"filter(mtcars, !is.na(cyl)) "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "43374600932c502f3b8f0614309b340f",
"grade": false,
"grade_id": "cell-4f35092c147ceab5",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"#... <- read_...(...) |>\n",
"# filter(!is.na(...), ... != ...)\n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"world_vaccination"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "d50e5aac8144c9643928d7940ecea565",
"grade": true,
"grade_id": "cell-4f295963a61ad122",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_1.1()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "41e0e0805a9c79617e69be1e1938d745",
"grade": false,
"grade_id": "cell-b246d38affa1166f",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 1.2** \n",
"
{points: 1}\n",
"\n",
"Create a scatter plot of the percentage of people vaccinated (y-axis) against year (x-axis) for all the regions in `world_vaccination`. Make sure to label your axes with human readable labels with an appropriate text size. \n",
"\n",
"*Assign your plot to an object called `world_vacc_plot`*."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "6486cb30225a78bdbf997fb6945fbfca",
"grade": false,
"grade_id": "cell-31e847db6b64c666",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"world_vacc_plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "e1c84fc9e01e602c71139b2875fe6c03",
"grade": true,
"grade_id": "cell-56bc18a4d58208c4",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_1.2()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "f18db28b30548953a970a2a0648eb300",
"grade": false,
"grade_id": "cell-318acc9c423ac732",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"You will probably find that this plot isn't the right size for your screen. Let's change the plot size so that the plot area is as big as it needs to be to clearly see the \"ink\" (dots). We do this using the `options` function from the `repr` R package. In past worksheets and tutorials we did this for you, from now on you need to do this yourself and choose an approprate plot size.\n",
"\n",
"The `options` function takes 2 arguments for plot size, `repr.plot.width` and `repr.plot.height`. Uncomment the first line of code in the code cell below and fill in the `...` to choose a more approprate size and and replot the figure afterwards below.\n",
"\n",
"*Note: if you get a weird error saying `unable to start device 'png'`, it's because you set your plot's width and height too large - try a smaller number for each. If you get an error saying `invalid 'width' / 'height' argument`, it may be because you set the width/height too small - try a larger number.*\n",
"\n",
"You'll also often need to change the font size in plots. For this, add `theme(text = element_text(size=....))` to your `ggplot` object, with a reasonable choice of font size (a decent starting point is `size = 20`).\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#options(repr.plot.width = ..., repr.plot.height = ...) \n",
"#world_vacc_plot <- world_vacc_plot +\n",
"# theme(text = element_text(size = 20))\n",
"world_vacc_plot"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "60c1ca7b084d078e4a2f0c80f514f34c",
"grade": false,
"grade_id": "cell-9df6590ba88a1529",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 1.3** Multiple Choice:\n",
"
{points: 1}\n",
"\n",
"Now that we see how the percentage of people vaccinated with each of these vaccines varies over time, we should now start to look if there is a difference between the percentage vaccinated between the two different diseases. What should we do next to compare the differences (if they exist) most effectively?\n",
"\n",
"A. Filter the data by the type of vaccine and make two separate plots\n",
"\n",
"B. Colour the data by the type of vaccine\n",
"\n",
"C. Have a different shaped \"dot\"/point for each type of vaccine\n",
"\n",
"D. Colour the data by the type of vaccine, and have a different shaped \"dot\"/point for each type of vaccine\n",
"\n",
"*Assign your answer to an object called `answer1.3`. Make sure your answer is an uppercase letter and is surrounded by quotation marks (e.g. `\"F\"`).*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "93919b610e0efb904f74da48c0e7f450",
"grade": false,
"grade_id": "cell-eff4b83a3aa5ecd4",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# Replace the fail() with your answer. \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "35f8e940c555f08e8a5eea8804d5fef9",
"grade": true,
"grade_id": "cell-de1ed1a45f987cbd",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_1.3()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "7434e88b7c7fa9cedd2802d2c9c5812f",
"grade": false,
"grade_id": "cell-a0d78ab0948d478b",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 1.4**\n",
"
{points: 1}\n",
"\n",
"Now that we know how we will separate the data for our visualization, let's do it. Start by copying your code from **Question 1.2**.\n",
"\n",
"Next, add an `aes` function inside of the `geom_point` function to map `vaccine` to colour and shape. So your `geom_point` function and layer should look something like this: \n",
"\n",
"```\n",
"geom_point(aes(colour = ..., shape = ...)) +\n",
"```\n",
"\n",
"Finally, make sure you change *all* the axes and legends so they have nicely formatted, human-readable labels. To do this, we will remove the `xlab` and `ylab` label functions and just use the more general `labs` function, specifying all the aesthetics we want to label:\n",
"\n",
"```\n",
"labs(x = \"...\", y = \"...\", colour = \"...\", shape = \"...\")\n",
"```\n",
"\n",
"*Assign your answer to an object called `compare_vacc_plot`.*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "cba3541a685d901d0e0acef9cdac389f",
"grade": false,
"grade_id": "cell-374fd332fce06441",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"compare_vacc_plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "a57f2fb5a422a63123cf6652cee26339",
"grade": true,
"grade_id": "cell-d644f60d1f60a559",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_1.4()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "37c0703ff4c928308b5a0a8e7bdaf53b",
"grade": false,
"grade_id": "cell-f4cb0b4284167707",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"Now we see that although the dates where the percentage vaccinated became > 0 for each vaccine type started out in different years, they both increased at similar rates and are currently resting at about the same amount of percentage vaccinated. There is some variation that still exists in the data however, and perhaps that could be attributed to region? Let's create some more visualizations to see if that is indeed the case!\n",
"\n",
"To get started, let's focus on the Polio vaccine data, and then we'll look at both together."
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "cc86ac034faa2f43086a9ff0f207d3c0",
"grade": false,
"grade_id": "cell-88236b86419d60b7",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 1.5**\n",
"
{points: 1}\n",
"\n",
"Create a data frame object named `polio` that contains only the rows where the `vaccine` is `\"polio\"`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "565811314f4fc5a94f5079351876328c",
"grade": false,
"grade_id": "cell-e3ea1eaccfcdb529",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"polio"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "4f56b3bc07e2ce03cefeec6ad5ce201e",
"grade": true,
"grade_id": "cell-96b08ba246959d81",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_1.5()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "fda81c24aacb5b4c7f7a7a5863b59324",
"grade": false,
"grade_id": "cell-a76fd8a76737dd65",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 1.6**\n",
"
{points: 1}\n",
"\n",
"Now create a scatter plot using the `polio` data where percentage vaccinated is on the y-axis, year is on the x-axis and each group has a different coloured point, and a different shape. Name it `polio_regions`. You might want to use `options` to change the plot size if the size of the last few plots isn't ideal for this plot."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "969a32ed614878eef8674513e37600c0",
"grade": false,
"grade_id": "cell-b8e28cbd972366a7",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"#... <- ...\n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"polio_regions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "ab5ffa2cabc41715b2ea371ebe134f48",
"grade": true,
"grade_id": "cell-80a368c34a543e78",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_1.6()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "eeb5c43c0f7183628315e44f6bd0d6c5",
"grade": false,
"grade_id": "cell-78cdf142395d1696",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 1.7.1**\n",
"
{points: 1}\n",
"\n",
"Although changing point colour and shape makes it easier for us to see the differences between multiple groups, at some point there are just too many groups to keep things straight. We are approaching this limit in the plot above, so we need to do something different... One thing we could try is to change the point to a line to reduce the noise/chaos of the plot above. We would also not have a shape. Do that in the cell below and name the plot object `polio_regions_line`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "ba3f55a2131f1265de0c5a7f1fbc54af",
"grade": false,
"grade_id": "cell-c803221869b8ae00",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"#... <- ...\n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"polio_regions_line"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "4439f145ad46cda56646259f1a04062c",
"grade": true,
"grade_id": "cell-9bc60c906bcd60b3",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_1.7.1()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "a6809ab22ffc9dd6abcd54d85ed78c83",
"grade": false,
"grade_id": "cell-7f961cecd0a71723",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"**Question 1.7.2**\n",
"
{points: 1}\n",
"\n",
"One thing that is still not ideal with the visualization above is the legend title is not very readable. Let's add another layer to `polio_regions_line` to do that. To do this we use the `labs` function and choose the aesthetic mapping (here `color`) that we want to apply the legend title to. Also, given that we created an object from our previous plot, we do not need to retype all our code, but instead can just say:\n",
"\n",
"```\n",
"[your plot object] <- [your plot object] +\n",
" [new layer code]\n",
"```\n",
"\n",
"*Assign your answer to an object called `polio_regions_line`*."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "a8530a48c4d02da0f0853679357a2f61",
"grade": false,
"grade_id": "cell-b6300558236b3514",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"#... <- polio_regions_line +\n",
"# labs(... = \"Region of the world\")\n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"polio_regions_line"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "742a303e5e5d7ae06d1c6ed5305b32f9",
"grade": true,
"grade_id": "cell-0cb2d6d52e5baf63",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_1.7.2()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "d77be3c8f86fe28fffc2a39b7a4d31f6",
"grade": false,
"grade_id": "cell-99db863d291c52b2",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 1.8**\n",
"
{points: 1}\n",
"\n",
"Now that we know how to effectively plot the percentage vaccinated against Polio over time for each region, how might we compare this to what we see for each region for the percentage vaccinated against Hepatitis B? In this case we would like two side-by-side or two vertically arranged plots. If that data are in the same data frame (as ours were in the `world_vaccination` data frame) then we can use a technique called facetting to do this. We saw facetting last week, and now we will take some time to learn it.\n",
"\n",
"There are two facetting functions in R, the one we will see here is `facet_grid`. The basic syntax for this `ggplot` layer is the following:\n",
"\n",
"```\n",
"# Stacks plots horizontally with one column per member of the category in COLUMN_X\n",
"facet_grid(cols = vars(COLUMN_X))\n",
"```\n",
"\n",
"or \n",
"\n",
"```\n",
"# Stacks plots vertically with one row per member of the category in COLUMN_X\n",
"facet_grid(rows = vars(COLUMN_X))\n",
"```\n",
"\n",
"Create a plot like the one named `polio_regions_line` but instead of using the `polio` data frame, use the `world_vaccination` data frame, and facet on the column `vaccine` so that the two plots are side-by-side. Name this plot object `side_by_side_world`. Make sure you set `options` to make the plot size fit well within the worksheet."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "63908ce206d5da14576a7e448e583a0b",
"grade": false,
"grade_id": "cell-1703a03640493439",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"#... <- ... +\n",
"# geom_...(...) +\n",
"# labs(...) +\n",
"# xlab(...) + \n",
"# ylab(...) +\n",
"# facet_grid(...)\n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"side_by_side_world"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "d19b190d595cb335cb359b229c8c8516",
"grade": true,
"grade_id": "cell-da960eda0165bd94",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_1.8()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "3c332b48c0d722f48bf1ece78b178796",
"grade": false,
"grade_id": "cell-bf8e150751b134f6",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 1.9.1**\n",
"
{points: 1}\n",
"\n",
"Now use `facet_grid` to arrange the same two plots vertically. Name this plot `vertical_world`. Again, make sure you set `options` to create a suitable plot size."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "9c4a915fd1000ed55abfc20c54bb225e",
"grade": false,
"grade_id": "cell-55bbd1d0a2ea4a40",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"vertical_world"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "b3eda0a1ae3e82706025f5197b22d839",
"grade": true,
"grade_id": "cell-2a2384fca721cc8a",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_1.9.1()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "48d5afed21a69f9b88d3ffd83167a444",
"grade": false,
"grade_id": "cell-8cba902e440bfbf8",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"Which arrangement is better? Depends on what you are asking! If you are interested in comparing the rate at which things changed over time, then the vertical arrangement is more effective. However, if you are interested in comparing the exact percentage values between the lines at certain points then the side-by-side arrangement is more effective."
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "ea2278d5ac001730f7e181682a7add43",
"grade": false,
"grade_id": "cell-6e7d28492998c804",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 1.9.2** Multiple Choice:\n",
"
{points: 1}\n",
"\n",
"Which WHO region had the greatest progress in the shortest period of time in either Hepatitis B and in Polio (using the data we plotted above)?\n",
"\n",
"\n",
"A. Americas\n",
"\n",
"B. Eastern Mediterranean\n",
"\n",
"C. Europe\n",
"\n",
"D. Western Pacific\n",
"\n",
"*Assign your answer to an object called `answer1.9.2`. Make sure your answer is an uppercase letter and is surrounded by quotation marks (e.g. `\"F\"`).*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "dfc9df86bf9d907b1ab41c87fb39f5b8",
"grade": false,
"grade_id": "cell-2f8d6a1dce2d67ae",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# Replace the fail() with your answer. \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "219f9eceea1e22d17d2bada22d76afcc",
"grade": true,
"grade_id": "cell-a69f9766adab9544",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_1.9.2()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "3643d9f2a06528de0f80081d7e3df0cd",
"grade": false,
"grade_id": "cell-5ded190fc1855d5b",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"## 2. Fast-Food Chains in the United States\n",
"\n",
"With their cheap meals and convenient drive-thrus, fast food restaurants are a growing demand in many countries. Despite their questionable ingredients and nutritional value, most Americans count on fast food in their daily lives (they are often delicious and so hard to resist...). \n",
"\n",
"\n",
"\n",
"Source: https://media.giphy.com/media/NS6SKs3Lt8cPHhe0es/giphy.gif\n",
"\n",
"According to Wikipedia,\n",
"> Fast food was originally created as a commercial strategy to accommodate the larger numbers of busy commuters, travelers and wage workers who often didn't have the time to sit down at a public house or diner and wait the normal way for their food to be cooked. By making speed of service the priority, this ensured that customers with strictly limited time (a commuter stopping to procure dinner to bring home to their family, for example, or an hourly laborer on a short lunch break) were not inconvenienced by waiting for their food to be cooked on-the-spot (as is expected from a traditional \"sit down\" restaurant). For those with no time to spare, fast food became a multi-billion dollar industry.\n",
"\n",
"Currently, fast food is the norm and lots of businesses are investing in advertisement as well as new ideas to make their chain stand out in the sea of restaurants. In fact, one business is hiring you. They want to know the layout of the landscape:\n",
"\n",
"1) Which is the most prevalent franchise on the west coast of the US? \n",
"\n",
"2) Which state has the highest number of fast-food restuarants? \n",
"\n",
"3) Is the most dominant franchise consistent across the west coast?\n",
"\n",
"In this assignment, you will pretend to assist in the opening of a new restaurant somewhere on the west coast of the United States (California, Oregon, or Washington). Your goal is to figure out which chain to recommend and figure out which state would be the least competitive.\n",
"\n",
"The columns in the dataset are:\n",
"\n",
"- `name` - The name of the restaurant\n",
"- `st` - State"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "ab4aabfe5cf2d7609d6cff74d8f4b21d",
"grade": false,
"grade_id": "cell-1d4483955210a104",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 2.1** Multiple Choice:\n",
"
{points: 1}\n",
"\n",
"From the list below, what are you *not* trying to determine:\n",
"\n",
"A. The west coast frachise with the greatest prevalence\n",
"\n",
"B. The least dominant franchise consistent across the west coast\n",
"\n",
"C. The state on the west coast with the greatest number of fast-food restuarants\n",
"\n",
"*Assign your answer to an object called `answer 2.1`. Make sure your answer is an uppercase letter and is surrounded by quotation marks (e.g. `\"F\"`).*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "22249bc8a73994f14c53adf51996c2f8",
"grade": false,
"grade_id": "cell-ee7c5c9ca8b83d19",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# Replace the fail() with your answer. \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "edbbc76401c08e09c497ef7370373408",
"grade": true,
"grade_id": "cell-22af5054ff59eadd",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_2.1()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "9c298347dc8bb90191aed7a0835deff4",
"grade": false,
"grade_id": "cell-2a0d906c102c421a",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 2.2**\n",
"
{points: 1}\n",
"\n",
"Read the `fast_food.csv` file (found in the `worksheet_04/data` directory) and assign it to an object called `fast_food`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "c97bc8992283bc3cf6938db3145718f7",
"grade": false,
"grade_id": "cell-84ec1117f0f1e0d4",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"fast_food"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "2d35b731f53add3496709dd46a3359fa",
"grade": true,
"grade_id": "cell-f61886d392c4a00a",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_2.2()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "5c68bb8a2358ad1e0f5a81b0a9790faf",
"grade": false,
"grade_id": "cell-b752f228aa364c90",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"**Question 2.2.1** Multiple Choice:\n",
"
{points: 1}\n",
"\n",
"What does each row in the dataset represent?\n",
"\n",
"A. The number of branches from a given franchise and state\n",
"\n",
"B. A unique branch of a given franchise in a given state\n",
"\n",
"C. An indicator of whether a given franchise is present in a given state\n",
"\n",
"*Assign your answer to an object called `answer 2.2.1`. Make sure your answer is an uppercase letter and is surrounded by quotation marks (e.g. `\"F\"`).*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "d4d9acfc8c7d410bcb2deee3c498ac67",
"grade": false,
"grade_id": "cell-3b610030c80671d3",
"locked": false,
"schema_version": 3,
"solution": true,
"task": false
}
},
"outputs": [],
"source": [
"# Replace the fail() with your answer. \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "c9486bd9b0cfb5a7ca2e33cfeb4ba941",
"grade": true,
"grade_id": "cell-d5c80de7a7a08e65",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"test_2.2.1()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "6692b2c263cd485f22fc79183fc192ab",
"grade": false,
"grade_id": "cell-0df97ab2333937cb",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 2.3** \n",
"
{points: 1}\n",
"\n",
"Next, find the top 9 restaurants (in terms of number of locations) on the west coast (in the states \"CA\", \"WA\" or \"OR\") and name them `top_restaurants`. Fill in the `...` in the cell below, removing the `fail()`. Recall that the `n()` function counts rows.\n",
"\n",
"*Assign your answer to an object called `top_restaurants`.*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "c2f92b81ad5d8ba0494b7c18d0546848",
"grade": false,
"grade_id": "cell-5c06ffd85d7fa572",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"#... <- fast_food |>\n",
"# filter(st %in% c(\"CA\", \"WA\", \"OR\")) |> \n",
"# group_by(...) |>\n",
"# ...(count = n()) |>\n",
"# ...(..., n = ...)\n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"top_restaurants"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "1be8488f047031257476d0d31ffb4dfd",
"grade": true,
"grade_id": "cell-f2aa06843158a15e",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_2.3()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "dbb03c09caf9c0c98016834765239fe9",
"grade": false,
"grade_id": "cell-49f4f43165cf12c8",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 2.4** \n",
"
{points: 1}\n",
"\n",
"Even though we can use the table above to answer the question: \"1) Which is the most prevalent franchise on the west coast of the US?\" A table is not always the clearest way of showing information (although sometimes it might be). In our case a bar plot could be more helpful, so let's create one!\n",
"\n",
"Plot the counts for the top 9 fast food restaurants on the west coast as a bar chart using `geom_bar`. The number of restaurants should be on the y-axis and the restaurant names should be on the x-axis. Because we are not counting up the number of rows in our data frame, but instead are plotting the actual values in the `count` column, we need to use the `stat = \"identity\"` argument inside `geom_bar`.\n",
"\n",
"To do this fill in the `...` in the cell below. Copy and paste your finished answer into the `fail()`. Make sure to label your axes and choose an appropriate figure size using `options`.\n",
"\n",
"*Assign your answer to an object called `count_bar_chart`.*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "9f82be543b81de0ee0fe92c97523b674",
"grade": false,
"grade_id": "cell-7fa524ccd31a0eb3",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"#... <- ...(..., aes(x = ..., y = ...)) + \n",
"# geom_bar(...) +\n",
"# xlab(...) +\n",
"# ylab(...)\n",
"\n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"count_bar_chart"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "21ad64d6b88e1c637bd45b360a0e2e0a",
"grade": true,
"grade_id": "cell-75b9ba0facc9e21e",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_2.4()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "19bbbfa1146d22e4053d3b45132a1261",
"grade": false,
"grade_id": "cell-7a9798d1a03634b9",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"**Question 2.5**\n",
"
{points: 1}\n",
"\n",
"The x-axes labels don't look great unless you make the bars on the bar plot above quite wide, wider than are actually useful or effective. What can we do? There are two good solutions to this problem.\n",
"\n",
"**Part A:** We can add a `theme` layer and rotate the labels. Choose an angle that you think is appropriate. Choose something between 20 and 90 for the `angle` argument. Use the `hjust = 1` argument to ensure your labels don't sit on top of the bars as you rotate them (try removing that argument and see what happens...).\n",
"\n",
"*Name the resulting plot count_bar_chart_A.*\n",
"\n",
"**Part B:** We can also simply remake the plot with horizontal bars by swapping the aesthetic mapping. Specify that the `name` variable should be on the `y` axis, and the `count` variable should be on the `x` axis. Make sure to swap your axis labels too!\n",
"\n",
"*Name the resulting plot count_bar_chart_B.*\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "53496e5d30f2f570e1d3fa3434122f46",
"grade": false,
"grade_id": "cell-74b1fc82a7200158",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"#PART A\n",
"#... <- ... + \n",
"# theme(axis.text.x = element_text(angle = ..., hjust = 1))\n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"count_bar_chart_A\n",
"\n",
"#PART B\n",
"#count_bar_chart_B <- ...(..., aes(x = ..., y = ...)) + \n",
"# geom_bar(...) +\n",
"# xlab(...) +\n",
"# ylab(...)\n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"count_bar_chart_B"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "334c564b52b54146e77fb68759874dbb",
"grade": true,
"grade_id": "cell-6fc37492ce4c8caf",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_2.5_A()\n",
"test_2.5_B()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "65cef3649742aba2d31702f6bd72372d",
"grade": false,
"grade_id": "cell-09a3f2ba6c0c15e4",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 2.6**\n",
"
{points: 1}\n",
"\n",
"Which is the most prevalent franchise on the west coast? Save your answer as `answer2.6` and be sure to surround the restuarant name with quotations. Pay attention to case and punctuation when answering."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "fb245e96e5f775d916d433bd5db01d3a",
"grade": false,
"grade_id": "cell-4b5e9ae3b501ff80",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "fc4df11e1375768f99df3eceb9d0ad5a",
"grade": true,
"grade_id": "cell-7e1f5a0036666e46",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_2.6()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "223409f7252db26235ee5efd14e33123",
"grade": false,
"grade_id": "cell-21bc1492a7923acd",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 2.7** \n",
"
{points: 1}\n",
"\n",
"Next, let's find which state on the west coast has the highest number of those top 9 fast-food restuarants we found earlier. To do this we need to use the names in `top_restaurants` to get the counts of each restaurant in each of the 3 states from the `fast_food` data frame. You will need to use `semi_join` to do this (to get the intersection of two data frames). Name this data frame `state_counts`. Fill in the `...` in the cell below. Copy and paste your finished answer into the `fail()`.\n",
"\n",
"*If you are interested in learning more about joining data frames in R, see [this cheatsheet](https://stat545.com/bit001_dplyr-cheatsheet.html).*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "89b3aea20402778e0eea9c2aab3bced2",
"grade": false,
"grade_id": "cell-fdd4333a78788519",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"#... <- fast_food |>\n",
"# semi_join(top_restaurants) |> # semi_join gives the intersection of two data frames\n",
"# filter(st %in% c(\"CA\", \"WA\", \"OR\")) |> \n",
"# ...(...) |>\n",
"# ...(count = n()) \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"state_counts"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "40b21c37d45321b72fa71ff0135a80dc",
"grade": true,
"grade_id": "cell-53713f7578969f5c",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_2.7()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "10f63eb2d8c699be5bbcd1fec7cd4ff9",
"grade": false,
"grade_id": "cell-d7ee2bd6b5df79ae",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 2.8**\n",
"
{points: 1}\n",
"\n",
"Now, create a bar plot that has restaurant count on the y-axis and US state on the x-axis. Name the plot `state_counts_plot`. Remember to choose an appropriate plot size using `options`. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "0aeeb0042a7ae9170c7ed36d1ab388f9",
"grade": false,
"grade_id": "cell-b7d101d1906d201c",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"#... <- ...\n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"state_counts_plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "42c287b05f90f7967b43f52768b8ca55",
"grade": true,
"grade_id": "cell-3ee58280015e1838",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_2.8()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "065f7c60ae156b0779f2d20eed2a6be1",
"grade": false,
"grade_id": "cell-b50e50c135e6d682",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 2.9.0**\n",
"
{points: 1}\n",
"\n",
"Which state (CA, OR, WA) has the highest number of fast-food restuarants? Save your answer as `answer2.9.0` and be sure to surround the state initialism with quotations (e.g. `\"NY\"`). Pay attention to case and punctuation when answering."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "16289d6088e0eb00dade0d06b3e7c75a",
"grade": false,
"grade_id": "cell-3808cf146c117d12",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# Replace the fail() with your answer. \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "f1b3d0fc56745628db20a58626856889",
"grade": true,
"grade_id": "cell-a17cc0ffac7cd795",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_2.9.0()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "18fbe3367ad55765d5a741e82d5bdfc1",
"grade": false,
"grade_id": "cell-d202e7ffd51f7ed6",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"Consider the populations of California (39.512 million), Oregon (4.217 million) and Washington (7.615 million) (source: [United States Census Bureau](https://www.census.gov/data/tables/time-series/demo/popest/2010s-state-total.html), visited on April 2020). Discuss with your neighbour about whether using the raw restaurant count for each state is the best measure of competition? Would restaurant per capita be a better alternative?"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "225ec69369c504f67d9cf2b95ba665d4",
"grade": false,
"grade_id": "cell-f1cdfd674e10939c",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"Calculate the restaurant per capita for the states on the west coast by uncommenting and filling in the `...` in the code below."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# population <- c(39.512, 4.217, 7.615)\n",
"\n",
"# state_counts |>\n",
"# mutate(n_per_capita = ... / population)"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "f6ac4031e35dff642a0f95fed87f1c1e",
"grade": false,
"grade_id": "cell-81dda6467a7fbc87",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"**Question 2.9.1** Multiple Choice:\n",
"
{points: 1}\n",
"\n",
"Which state has the highest number of fast food restaurants per capita?\n",
"\n",
"A. Washington\n",
"\n",
"B. California\n",
"\n",
"C. Oregon\n",
"\n",
"*Assign your answer to an object called `answer2.9.1`. Make sure your answer is an uppercase letter and is surrounded by quotation marks (e.g. `\"F\"`).*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "54c9601439a93924ddf69212d4e74ce8",
"grade": false,
"grade_id": "cell-7df84a13da5e51bc",
"locked": false,
"schema_version": 3,
"solution": true,
"task": false
}
},
"outputs": [],
"source": [
"# Replace the fail() with your answer. \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "7612a36e110d01b198af6f526cc8185a",
"grade": true,
"grade_id": "cell-caee5ba3ec18fa8c",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"test_2.9.1()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "c974d73ede01f9cda3fbb2284a925ea3",
"grade": false,
"grade_id": "cell-6ae4fef0681d6b96",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"**Question 2.9.2** \n",
"
{points: 1}\n",
"\n",
"Is the most dominant/top franchise consistent across the west coast? To answer this question we need a data frame that has three columns: `name` (restaurant), `st` and `count` (restaurant count). We will need to use the `semi-join` strategy as we did above to use the names in `top_restaurants` to get the counts of each restaurant in each of the 3 states from the `fast_food` data frame. This time, however, we'll need to `group_by` both `name` and `st`. Name this new data frame `top_n_state`. We only want to look at those top 9 fast-food restuarants we found earlier."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "1458e1a436485271a37ced1a1928b571",
"grade": false,
"grade_id": "cell-fa13c7c54d724542",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"#... <- fast_food |>\n",
"# semi_join(top_restaurants) |> # semi_join gives the intersection of two data frames\n",
"# filter(st %in% c(\"CA\", \"WA\", \"OR\")) |> \n",
"# ...(..., ...) |>\n",
"# ...(...) \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"top_n_state"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "c0b02d24c1973f0e0a8fa6eb368e3336",
"grade": true,
"grade_id": "cell-58b0fb2c06951419",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_2.9.2()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "f54b8945e931c6dcdf007d448ef8b5d4",
"grade": false,
"grade_id": "cell-bc917b8d65a605c2",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 2.9.3** \n",
"
{points: 1}\n",
"\n",
"Plot the counts (y-axis) for the top 9 fast food restaurants on the west coast **per US State** (x-axis), as a bar chart using `geom_bar`. Use `fill = name` inside `aes` to color the restaurant's by name. Use `position = \"dodge\"` inside `geom_bar` to group the bars by state. To rename the legend, use a `labs` layer. This time within `labs` use the `fill` argument instead of color (this is because you need to modify the asthetic that the legend was made from, here it was fill, not color as earlier in the worksheet).\n",
"\n",
"To do this fill in the `...` in the cell below. Copy and paste your finished answer into the `fail()`. Make sure to label your axes and choose an appropriate plot size. \n",
"\n",
"*Assign your answer to an object called `top_n_state_plot`.*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "2c2669cb8df54e7178baca0e36512955",
"grade": false,
"grade_id": "cell-e76e0bf48a0e8854",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"#... <- ggplot(..., aes(x = ..., y = ..., fill = ...)) + \n",
"# ...(stat = ..., position = \"...\") + \n",
"# xlab(...) +\n",
"# ylab(...) +\n",
"# labs(fill = \"Restaurant\") \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"top_n_state_plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "a5960e5b94ec323e5d5cd91075fe8131",
"grade": true,
"grade_id": "cell-ed385a60b4c8a6d0",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_2.9.3()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "c0cb3e5c76c5f210203c80ef31d45a95",
"grade": false,
"grade_id": "cell-ff61d705f3a66bac",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"How easy is that to compare the restaurants and states to answer our question: Is the most dominant/top franchise consistent across the West-Coast? If we carefully look at this plot we can pick answer this question, but it takes us a while to process this. If we instead visualize this as a stacked bar chart using proportions instead of counts we might be able to do this easier (making it a more effective visualization)."
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "cce2e73ccc5492e4ad9ca73f6a788ce3",
"grade": false,
"grade_id": "cell-fbbbd065920901d2",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 2.9.4** \n",
"
{points: 1}\n",
"\n",
"Copy your code from Question 2.9.3 and modify `position = \"dodge\"` to `position = \"fill\"` to change from doing a grouped bar chart to a stacked bar chart with the data represented as proportions instead of counts. \n",
"\n",
"*Assign your answer to an object called `top_n_state_plot`*."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "6e59c2eb0c3ff80d463dd12c808c2369",
"grade": false,
"grade_id": "cell-8d848ab3e4d34d85",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"#... <- ...\n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer\n",
"top_n_state_plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "99e00f2fe7ac461aef2af579129aa895",
"grade": true,
"grade_id": "cell-b90d158867cf1c27",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_2.9.4()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "786c82c3334c00bb450c53e10275d9fd",
"grade": false,
"grade_id": "cell-18024b55d0ecc8f0",
"locked": true,
"schema_version": 3,
"solution": false
}
},
"source": [
"**Question 2.9.5** \n",
"
{points: 1}\n",
"\n",
"Is the most dominant franchise consistent across the west coast? Answer `\"yes\"` or `\"no\"`. Save your answer as `answer2.9.5` and be sure to surround the answer with quotations. Pay attention to case and punctuation when answering."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "e14c8ad1be30e5460c71ebe59e8df9d5",
"grade": false,
"grade_id": "cell-84b61b1043757d6f",
"locked": false,
"schema_version": 3,
"solution": true
}
},
"outputs": [],
"source": [
"# Replace the fail() with your answer. \n",
"\n",
"# your code here\n",
"fail() # No Answer - remove if you provide an answer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "f2d01f7aa898725f907b1b5bb830a38a",
"grade": true,
"grade_id": "cell-0eb8e20187b2bfa2",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false
}
},
"outputs": [],
"source": [
"test_2.9.5()"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "markdown",
"checksum": "4b8d6a261273277f11cec7b88797df56",
"grade": false,
"grade_id": "cell-ed421b97dac101b5",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"source": [
"We are just scratching the surface of how to create effective visualizations in R. For example, we haven't covered how to change from the default colors palette `ggplot2` provides. We'll learn more in the tutorial, but it's a big world out there; to learn more, visit the links in the reading and practice, practice, practice! Go forth and make beautiful and effective plots!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "b4b2df9ec00260ae57da39baac3653ce",
"grade": false,
"grade_id": "cell-e253b5cd13763b73",
"locked": true,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [],
"source": [
"source(\"cleanup.R\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "4.3.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}