Lab 1: Airbnbs in NYC

Airbnb in NYC (or your city)

Airbnb has had a disruptive effect on the hotel, rental home, and vacation industry throughout the world. The success of Airbnb has not come without controversies, with critics arguing that Airbnb has adverse impacts on housing and rental prices and also on the daily lives of people living in neighborhoods where Airbnb is popular. This controversy has been particularly intense in NYC, where the debate been Airbnb proponents and detractors eventually led to the city imposing strong restrictions on the use of Airbnb. If you find this issue interesting and want to go deeper, there is the potential for an interesting project that brings in hotels (which have interesting regulations in NYC), hotel price data, and rental data and looks at these things together.

Because Airbnb listings are available online through their website and app, it is possible for us to acquire and visualize the impacts of Airbnb on different cities, including New York City. This is possible through the work of an organization called inside airbnb

Instructions

  1. Complete the assigned questions in a quarto notebook (I recommend using this file as a template) and render the final document to a pdf file.

  2. Submit both the pdf file and the qmd source file that you used to create the pdf to brightspace.

Packages

We’ll use the tidyverse package for much of the data wrangling and visualisation, and the ggridges package to make a ridge plot in the last exercise. You may need to install ggridges if you haven’t already, you can do that using:

install.packages("ggridges")

Then make sure to load both packages:

Data

The data for this assignment can be found on my github page by clicking here and downloading nycbnb.csv

You can read the data into R using the command:

nycbnb = read_csv("https://github.com/georgehagstrom/DATA607Fall2025/blob/master/data/nyc_airbnb_listings_short.csv")

This will download it from my site and read it directly, but you may want to download it into a local directory and load it from there as well. In that case you can use read_csv(where your file is located) to laod it.

You can view the dataset as a spreadsheet using the View() function. Note that you should not put this function in your R Markdown document, but instead type it directly in the Console, as it pops open a new window (and the concept of popping open a window in a static document doesn’t really make sense…). When you run this in the console, you’ll see the following data viewer window pop up.

Exercises

Problem 1. Provide a basic description of the dataset:

  • How many observations (rows) does the dataset have? Instead of hard coding the number in your answer, use inline code. - Run View(nycbnb) in your Console to view the data in the data viewer. What does each row in the dataset represent?

Each column represents a variable. We can get a list of the variables in the data frame using the names() function.

names(nycbnb)

You can find descriptions of each of the variables in the help file for the dataset, which you can find online at the inside airbnb data dictionary. There are two additional variables that have been estimated: occupancy (defined as the fraction of days that the airbnb is rented) and revenue (average revenue per day).

Problem 2. For this question, you will make a visualization exploring several factors that may affect revenue: the neighborhood, the number of people that the airbnb can accomodate, and whether the host is a superhost.

  • Pick one of the five boroughs of NYC (Manhattan, Queens, Brooklyn, the Bronx, or Staten Island) and calculate the number of listings in each neighborhood of that borough. Filter the data to find only the listings for the five most popular neighborhoods by the total number of listings in your chosen borough that also accommodates fewer than 5 people. Also filter out listings where the value of is_host_superhost is NA.

  • Create a faceted plot (using facet grid) where each facet represents a combination of neighborhood and accommodates variables in your filtered data frame and displays the distribution of the revenue variable for superhosts and non-superhosts (hint: in the aesthetic function use the variable is_host_superhost for the group, fill, and color). Use the alpha aesthetic to make both distributions visible, and think critically about the best geom to compare the distributions across each facet. Along with your visualization, include your reasoning for the layout you chose for your facets and describe the relationship that your graph shows.

  • LLM Prompting Exercise: It can be challenging to make faceted plots with large numbers of facets legible, especially if you are just learning ggplot for the first time. What commonly occurs is that the plot labels are too large and the plot elements are nearly invisible. This can be fixed using more advanced features of ggplot. Look at the plot you created for the previous part and identify any ways you think it could be improved (if your plot is nearly perfect already congratulations, you can make a small stylistic change). Choose an Large Language Model (Claude Opus/Sonnet, ChatGPT, Gemini, DeepSeek etc) and prompt it to improve the issues that you identified in the previous part. Report the prompt that you used here as well as the code that was generated. Did the code run and how did it change your plot?

Problem 3. Exploring Different Types of Hosts

For this exercise we are going to explore how the calculated_host_listings_count variable, which corresponds to the number of listings that the host of that listing has citywide. Listings where calculated_host_listings_count are the only listing for a given host, and if calculated_host_listings_count is 100, it means that the host of this listing has 100 total listings. This variable thus differentiates hosts who use airbnb for their personal property or a single apartment from businesses that use airbnb to list hundreds of apartments.

  • Select for the 10 neighborhoods citywide with the most listings and calculate the mean and median of calculated_host_listings_count for listings in each neighborhood. What pattern do you see in the variation of host listings count between neighborhoods?

  • Filter the data to exclude listings whose value of first_review is later than January 1st, 2016 and repeat the calculations of the previous part. How have the mean values of calculated_host_listings_count changed the neighborhoods?

  • Use mutate to create a new variable in your filtered data frame which differentiates between listings hosted by a large company (calculated_host_listings_count > 10) and those not. Make a ridge plot of the the revenue distribution of listings in each neighborhood (use geom_density_ridges) using the fill aesthetic to separately plot the revenue distributions for listings hosted by a large company and those not. Restrict the x-axis to revenue between 0 and 300 using scale_x_continuous. Compute the mean revenue across all listings between the two categories and compare it to the results shown in your plot. Do you have any explanations for what might be happening?