library(tidyverse)
Click on the link provided in the slides to create your own private repo for this exercise.
Go to the ae-03-[GITHUB USERNAME]
repo on GitHub that you created
Click on the green Code button, Use HTTPS, and click on the clipboard icon to copy the repo URL.
Go to https://vm-manage.oit.duke.edu/containers and login with your Duke NetID and Password. Click to log into the Docker container RStudio - statistics application with Rmarkdown and knitr support. You should now see the RStudio environment.
Go to File -> New Project -> Version Control -> Git.
Copy and paste the URL of your assignment repo into the dialog box Repository URL. You can leave Project Directory Name empty. It will default to the name of the GitHub repo.
Click Create Project, and the files from your GitHub repo will be displayed the Files pane in RStudio.
Before we start the exercise, we need to configure your git so that RStudio can communicate with GitHub. This requires two pieces of information: your email address and your name.
Type the following lines of code in the Console in RStudio filling in your GitHub username and email address associated with your GitHub account.
library(usethis)
use_git_config(user.name= "github username", user.email="your email")
RStudio and GitHub can now communicate with each other and you are ready to do the exercise!
The data contains information about Airbnb listings in Madrid, Spain. The data originally come from Kaggle, and it has been modified for this exercise.
Use the code below to load the data from the .csv file.
madbnb <- read_csv("data/madbnb.csv")
The dataset you’ll be using is called madbnb
. Run View(madbnb)
in the console to view the data in the data viewer. What does each row in the dataset represent?
The madbnb
data set has 19905 observations (rows).
How many columns (variables) does the dataset have? Instead of hard coding the number in your answer, use the function ncol()
to write your answer in inline code. Hint: Use the statement above as a guide.
Knit to see the updates.
Fill in the code below to create a histogram to display the distribution of price
. Once you have modified the code, remove the option eval = FALSE
from the code chunk header. Knit again to see the updates.
ggplot(data = ___, mapping = aes(x = ___)) +
geom_histogram()
Now let’s look at the distribution of price for each neighborhood. To do so, we will make a faceted histogram where each facet represents a neighborhood and displays the distribution of price for that neighborhood.
Fill in the code below to create the faceted histogram with informative labels. Once you have modified the code, remove the option eval = FALSE
from the code chunk header. Knit again to see the updates.
Hint: Run names(madbnb)
in the console to get a list of variable names. Note how the variable for neighborhood is spelled in the data set.
ggplot(data = ___, mapping = aes(x = ___)) +
geom_histogram() +
facet_wrap(~___) +
labs(x = "______",
title = "_______",
subtitle = "Faceted by ______")
From the plots in Part 3, you might notice that the large number of listinings in one neighborhood is obscuring our ability to see the histograms for prices in all of the other neighborhoods. Fill in the code below as you did in Part 3, but now also change the scales
for each histogram. You can choose scales
= “free_x”, scales
= “free_y”, or scales
= “free”. Choose the option that you think best solves this issue.
Once you have modified the code, remove the option eval = FALSE
from the code chunk header. Knit again to see the updates.
ggplot(data = ___, mapping = aes(x = ___)) +
geom_histogram() +
facet_wrap(~___, scales = "_____") +
labs(x = "______",
title = "_______",
subtitle = "Faceted by ______")
How would you describe the distribution of price in general? How do neighborhoods compare to each other in terms of price?
If you made any changes since the last knit, knit again to get the final version of the AE.
Check the box next to each document in the Git tab (this is called “staging” the changes). Commit the changes you made using an simple and informative message.
Use the green arrow to push your changes to your repo on GitHub.
Check your repo on GitHub and see the updated files.