Photo by Madeleine Kohler on Unsplash
Once upon a time, people travelled all over the world, and some stayed in hotels and others chose to stay in other people’s houses that they booked through Airbnb.
Recent developments in Edinburgh regarding the growth of Airbnb and its impact on the housing market mean that a better understanding of Airbnb listings is needed. Using data provided by Airbnb, we can explore how Airbnb availability and prices vary by neighbourhood.
Open the project for this assignment in the course Posit Cloud workspace.
Open the R Markdown document hw-02.Rmd and render it before making any changes.
Make sure the document renders without errors. This is a useful first check that the project, packages, data, and files are all working correctly.
Before we introduce the data, let’s warm up with a simple exercise.
🧶 ✅ Throughout this assignment, remember to render your document regularly. After rendering, check the output to make sure your code, figures, and written responses appear as you expect.
We’ll use the tidyverse package for much of the data wrangling and visualization.
We will also use the ggridges package to make ridgeline plots.
You can load them by running the following:
If one of these packages is not installed, run the appropriate install.packages() command in your Console:
You only need to install a package once.
Do not put install.packages() in the code you render for your assignment.
The Airbnb data for this assignment are stored in the data folder of your project.
Load the data using:
You can view the dataset as a spreadsheet using the View() function.
Run this in the Console rather than in your R Markdown document:
View() opens an interactive data viewer, so it does not make sense to include it in a rendered document.
You can see the names of the variables in the dataset using:
Hint: The Markdown Quick Reference sheet has an example of inline R code that might be helpful. You can access it from the Help menu in RStudio. It is also referenced in this section of the R Markdown Cookbook.
✏️ How many observations (rows) does the dataset have? Instead of hard coding the number in your answer, use inline R code.
✏️ Run View(edibnb) in your Console to view the data in the data viewer.
What does each row in the dataset represent?
Hint: It’s something you can book.
🧶 ✅ Write your answers under Exercises 1 and 2, then render the document. Check the rendered document to make sure your answers appear correctly and that the inline R code in Exercise 1 displays a number rather than code.
Each column represents a variable.
We can get a list of the variables in the data frame using the names() function.
Note: The plot will give a warning about some observations with non-finite values for price being removed. Don’t worry about the warning. It simply means that some listings in the data don’t have prices available, so they can’t be plotted.
Think critically about whether it makes more sense to stack the facets on top of each other in a column, lay them out in a row, or wrap them around.
Along with your visualization, include your reasoning for the layout you chose for your facets.
Let’s deconstruct this code:
ggplot() is the function we are using to build our plot in layers.🧶 ✅ Complete the code for Exercise 3 and write your response underneath it. Render the document and check that the histogram appears correctly, the facets are readable, and your written explanation appears with the figure.
Hint: 4a will give you the names you will use to filter the neighbourhoods before making the plot in 4b.
New term: Whenever you have more than one pipe
|>, it is called a pipeline 😎.
Use a single pipeline to identify the neighbourhoods with the top five median listing prices.
Hint: Did your pipeline return NAs for
the median listing prices? Use ?median to find out how the
argument na.rm might be useful in your code.
In another pipeline, filter the data for these five neighbourhoods and make ridgeline plots showing the distributions of listing prices in these neighbourhoods.
Hint: Check out the tutorial on R Graph Gallery for an example of how to make a ridgeline plot.
✏️ In a third pipeline, calculate the minimum, mean, median, standard deviation, IQR, and maximum listing price in each of these neighbourhoods.
Use the visualization and summary statistics together to describe the distribution of listing prices in these neighbourhoods.
Your final answer for Exercise 4 should include three pipelines, one of which ends in a visualization, as well as a written interpretation.
🧶 ✅ Complete all three parts of Exercise 4 and render the document. Check that all three pipelines run, the ridgeline plot is visible and readable, the summary statistics appear, and your interpretation refers to both the visualization and the numerical summaries.
review_scores_rating) across neighbourhoods. You get to decide what type of visualization to create, and there is more than one correct answer! In your answer, include a brief interpretation of how Airbnb guests rate properties in general and how the neighbourhoods compare to each other in terms of their ratings.Tip: Looking for ideas? Check out R Graph Gallery. What types of graphs could you use to display a distribution? Which ones have we learned so far in class?
🧶 ✅ Complete Exercise 5 and render your document one final time. Read through the rendered document from beginning to end. Make sure all of your code runs, all figures and output appear correctly, and every exercise marked with ✏️ includes a written response before you submit your work.