library(tidyverse)
library(ggplot2)
library(readr)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Challenge 5
Challenge Overview
Today’s challenge is to:
- read in a data set, and describe the data set using both words and any supporting information (e.g., tables, etc)
- tidy data (as needed, including sanity checks)
- mutate variables as needed (including sanity checks)
- create at least two univariate visualizations
- try to make them “publication” ready
- Explain why you choose the specific graph type
- Create at least one bivariate visualization
- try to make them “publication” ready
- Explain why you choose the specific graph type
Read in data
<- read.csv("_data/AB_NYC_2019.csv")
data head(data)
id name host_id host_name
1 2539 Clean & quiet apt home by the park 2787 John
2 2595 Skylit Midtown Castle 2845 Jennifer
3 3647 THE VILLAGE OF HARLEM....NEW YORK ! 4632 Elisabeth
4 3831 Cozy Entire Floor of Brownstone 4869 LisaRoxanne
5 5022 Entire Apt: Spacious Studio/Loft by central park 7192 Laura
6 5099 Large Cozy 1 BR Apartment In Midtown East 7322 Chris
neighbourhood_group neighbourhood latitude longitude room_type price
1 Brooklyn Kensington 40.64749 -73.97237 Private room 149
2 Manhattan Midtown 40.75362 -73.98377 Entire home/apt 225
3 Manhattan Harlem 40.80902 -73.94190 Private room 150
4 Brooklyn Clinton Hill 40.68514 -73.95976 Entire home/apt 89
5 Manhattan East Harlem 40.79851 -73.94399 Entire home/apt 80
6 Manhattan Murray Hill 40.74767 -73.97500 Entire home/apt 200
minimum_nights number_of_reviews last_review reviews_per_month
1 1 9 2018-10-19 0.21
2 1 45 2019-05-21 0.38
3 3 0 NA
4 1 270 2019-07-05 4.64
5 10 9 2018-11-19 0.10
6 3 74 2019-06-22 0.59
calculated_host_listings_count availability_365
1 6 365
2 2 355
3 1 365
4 1 194
5 1 0
6 1 129
Briefly describe the data
This dataset contains data for AirBNB hotels and rooms available for booking in New York City for the year 2019. It has 16 columns with details ranging from booking dates, locations to room type and reviews.
Tidy Data (as needed)
Is your data already tidy, or is there work to be done? Be sure to anticipate your end result to provide a sanity check, and document your work here.
I am tidying the data to remove the N/A values in reviews_per_month
column with 0.
<- data %>% replace_na(list(reviews_per_month = 0)) tidy_data
Are there any variables that require mutation to be usable in your analysis stream? For example, do you need to calculate new values in order to graph them? Can string values be represented numerically? Do you need to turn any variables into factors and reorder for ease of graphics and visualization?
head(tidy_data)
id name host_id host_name
1 2539 Clean & quiet apt home by the park 2787 John
2 2595 Skylit Midtown Castle 2845 Jennifer
3 3647 THE VILLAGE OF HARLEM....NEW YORK ! 4632 Elisabeth
4 3831 Cozy Entire Floor of Brownstone 4869 LisaRoxanne
5 5022 Entire Apt: Spacious Studio/Loft by central park 7192 Laura
6 5099 Large Cozy 1 BR Apartment In Midtown East 7322 Chris
neighbourhood_group neighbourhood latitude longitude room_type price
1 Brooklyn Kensington 40.64749 -73.97237 Private room 149
2 Manhattan Midtown 40.75362 -73.98377 Entire home/apt 225
3 Manhattan Harlem 40.80902 -73.94190 Private room 150
4 Brooklyn Clinton Hill 40.68514 -73.95976 Entire home/apt 89
5 Manhattan East Harlem 40.79851 -73.94399 Entire home/apt 80
6 Manhattan Murray Hill 40.74767 -73.97500 Entire home/apt 200
minimum_nights number_of_reviews last_review reviews_per_month
1 1 9 2018-10-19 0.21
2 1 45 2019-05-21 0.38
3 3 0 0.00
4 1 270 2019-07-05 4.64
5 10 9 2018-11-19 0.10
6 3 74 2019-06-22 0.59
calculated_host_listings_count availability_365
1 6 365
2 2 355
3 1 365
4 1 194
5 1 0
6 1 129
All the variables are in correct format and are usable in the analysis.
Univariate Visualizations
I will attempt to plot the reviews_per_month of listings in NYC as this is the closest metric we can get for occupancy in these listings considering occupancy to be directly proportional to reviews.
To achieve this plot, I first aggregated the data to get the total reviews in a month for each neighborhood group.
= tidy_data %>% group_by(neighbourhood_group) %>%
df_agg summarise(total_reviews_per_month = sum(reviews_per_month),
.groups = 'drop')
head(df_agg)
# A tibble: 5 × 2
neighbourhood_group total_reviews_per_month
<chr> <dbl>
1 Bronx 1610.
2 Brooklyn 21105.
3 Manhattan 21158.
4 Queens 8879.
5 Staten Island 588.
ggplot(data=df_agg, aes(x=neighbourhood_group, y=total_reviews_per_month)) +
geom_bar(stat="identity") + labs(title = "Total Reviews Per Month")
Bivariate Visualization(s)
The pricing for each borough is also an important factor that is generally looked upon by customers before booking and is worth keeping track of.
%>%
tidy_data ggplot(aes(neighbourhood_group, price), fill = neighbourhood) +
geom_boxplot() +
labs(title = "Borough-wise pricing") +
theme_classic()