Challenge 5

challenge_5
Jaswanth Reddy Kommuru
air_bnb
Introduction to Visualization
Author

Jaswanth Reddy Kommuru

Published

May 10, 2023

library(tidyverse)
library(ggplot2)

knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)

Challenge Overview

Today’s challenge is to:

  1. read in a data set, and describe the data set using both words and any supporting information (e.g., tables, etc)
  2. tidy data (as needed, including sanity checks)
  3. mutate variables as needed (including sanity checks)
  4. create at least two univariate visualizations
  • try to make them “publication” ready
  • Explain why you choose the specific graph type
  1. Create at least one bivariate visualization
  • try to make them “publication” ready
  • Explain why you choose the specific graph type

R Graph Gallery is a good starting point for thinking about what information is conveyed in standard graph types, and includes example R code.

(be sure to only include the category tags for the data you use!)

Read in data

Read in one (or more) of the following datasets, using the correct R package and command.

  • cereal.csv ⭐
  • Total_cost_for_top_15_pathogens_2018.xlsx ⭐
  • Australian Marriage ⭐⭐
  • AB_NYC_2019.csv ⭐⭐⭐
  • StateCounty2012.xls ⭐⭐⭐
  • Public School Characteristics ⭐⭐⭐⭐
  • USA Households ⭐⭐⭐⭐⭐
bnbdata <- read.csv("~/Documents/601/601_Spring_2023/posts/_data/AB_NYC_2019.csv")
head(bnbdata)
    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
colnames(bnbdata)
 [1] "id"                             "name"                          
 [3] "host_id"                        "host_name"                     
 [5] "neighbourhood_group"            "neighbourhood"                 
 [7] "latitude"                       "longitude"                     
 [9] "room_type"                      "price"                         
[11] "minimum_nights"                 "number_of_reviews"             
[13] "last_review"                    "reviews_per_month"             
[15] "calculated_host_listings_count" "availability_365"              
dim(bnbdata)
[1] 48895    16
str(bnbdata)
'data.frame':   48895 obs. of  16 variables:
 $ id                            : int  2539 2595 3647 3831 5022 5099 5121 5178 5203 5238 ...
 $ name                          : chr  "Clean & quiet apt home by the park" "Skylit Midtown Castle" "THE VILLAGE OF HARLEM....NEW YORK !" "Cozy Entire Floor of Brownstone" ...
 $ host_id                       : int  2787 2845 4632 4869 7192 7322 7356 8967 7490 7549 ...
 $ host_name                     : chr  "John" "Jennifer" "Elisabeth" "LisaRoxanne" ...
 $ neighbourhood_group           : chr  "Brooklyn" "Manhattan" "Manhattan" "Brooklyn" ...
 $ neighbourhood                 : chr  "Kensington" "Midtown" "Harlem" "Clinton Hill" ...
 $ latitude                      : num  40.6 40.8 40.8 40.7 40.8 ...
 $ longitude                     : num  -74 -74 -73.9 -74 -73.9 ...
 $ room_type                     : chr  "Private room" "Entire home/apt" "Private room" "Entire home/apt" ...
 $ price                         : int  149 225 150 89 80 200 60 79 79 150 ...
 $ minimum_nights                : int  1 1 3 1 10 3 45 2 2 1 ...
 $ number_of_reviews             : int  9 45 0 270 9 74 49 430 118 160 ...
 $ last_review                   : chr  "2018-10-19" "2019-05-21" "" "2019-07-05" ...
 $ reviews_per_month             : num  0.21 0.38 NA 4.64 0.1 0.59 0.4 3.47 0.99 1.33 ...
 $ calculated_host_listings_count: int  6 2 1 1 1 1 1 1 1 4 ...
 $ availability_365              : int  365 355 365 194 0 129 0 220 0 188 ...
 bnbdata%>%
  select(`neighbourhood_group`) %>%
  distinct(.)
  neighbourhood_group
1            Brooklyn
2           Manhattan
3              Queens
4       Staten Island
5               Bronx

The dataset provides details about Airbnbs located in all boroughs of New York City. It comprises 16 columns and 48,895 entries, with each row providing information on a specific Airbnb such as its type, location, owner details, reviews, and more.

Briefly describe the data

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.

bnbdata <- bnbdata %>%
  mutate(reviews_per_month = ifelse(is.na(reviews_per_month), 0, reviews_per_month))

bnbdata <- bnbdata %>%
  filter(price > 0)

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?

Document your work here.

Univariate Visualizations

ggplot(bnbdata, aes(neighbourhood_group, fill = room_type)) + geom_bar() +
  theme_bw() +
  labs(title = "The number of available rooms and the type of rooms in each neighbourhood ", y = "Number of available rooms", x = "Neighbourhood")

Based on the graph, we can infer that Manhattan has the highest proportion of Airbnbs among all the neighborhood’s in NYC, while Staten Island has the lowest proportion. The order of boroughs in terms of proportion of Airbnbs is as follows: Manhattan, Brooklyn, Queens, Bronx, and Staten Island.

cheap_hotels <- bnbdata %>%
  arrange(price) %>%
  filter(row_number() <= 500)

ggplot(cheap_hotels, aes(x = price, fill = factor(price))) +
  geom_bar() +
  theme_bw() +
  labs(title = "Distribution of Prices for the 500 Most Affordable Rooms")

Bivariate Visualization(s)

ggplot(bnbdata) + 
  geom_point(mapping = aes(x = minimum_nights, y = price, color = price)) + 
  labs(x = "Minimum nights stayed",
       y = "Price in Dollars",
       title = "Relationship between Price and Minimum nights stayed")

From the above graph we can say how the minimum nights stayed is related to the price.

ggplot(bnbdata, aes(x = room_type, y = price, fill = room_type)) +
  geom_boxplot(alpha = 1) +
  scale_fill_manual(values = c("red", "blue", "green")) +
  theme_bw() +
  labs(title = "Price Distribution Based on Room Type")

We can gain insights into the price ranges for each room type from the above box plot.

Any additional comments?