Challenge 5

challenge_5
Abhinav Reddy Yadatha
AB_NYC_2019.csv
Introduction to Visualization
Author

Abhinav Reddy Yadatha

Published

May 14, 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 ⭐⭐⭐⭐⭐
ab_nyc_data <- read.csv("_data/AB_NYC_2019.csv")
head(ab_nyc_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
summary(ab_nyc_data)
       id               name              host_id           host_name        
 Min.   :    2539   Length:48895       Min.   :     2438   Length:48895      
 1st Qu.: 9471945   Class :character   1st Qu.:  7822033   Class :character  
 Median :19677284   Mode  :character   Median : 30793816   Mode  :character  
 Mean   :19017143                      Mean   : 67620011                     
 3rd Qu.:29152178                      3rd Qu.:107434423                     
 Max.   :36487245                      Max.   :274321313                     
                                                                             
 neighbourhood_group neighbourhood         latitude       longitude     
 Length:48895        Length:48895       Min.   :40.50   Min.   :-74.24  
 Class :character    Class :character   1st Qu.:40.69   1st Qu.:-73.98  
 Mode  :character    Mode  :character   Median :40.72   Median :-73.96  
                                        Mean   :40.73   Mean   :-73.95  
                                        3rd Qu.:40.76   3rd Qu.:-73.94  
                                        Max.   :40.91   Max.   :-73.71  
                                                                        
  room_type             price         minimum_nights    number_of_reviews
 Length:48895       Min.   :    0.0   Min.   :   1.00   Min.   :  0.00   
 Class :character   1st Qu.:   69.0   1st Qu.:   1.00   1st Qu.:  1.00   
 Mode  :character   Median :  106.0   Median :   3.00   Median :  5.00   
                    Mean   :  152.7   Mean   :   7.03   Mean   : 23.27   
                    3rd Qu.:  175.0   3rd Qu.:   5.00   3rd Qu.: 24.00   
                    Max.   :10000.0   Max.   :1250.00   Max.   :629.00   
                                                                         
 last_review        reviews_per_month calculated_host_listings_count
 Length:48895       Min.   : 0.010    Min.   :  1.000               
 Class :character   1st Qu.: 0.190    1st Qu.:  1.000               
 Mode  :character   Median : 0.720    Median :  1.000               
                    Mean   : 1.373    Mean   :  7.144               
                    3rd Qu.: 2.020    3rd Qu.:  2.000               
                    Max.   :58.500    Max.   :327.000               
                    NA's   :10052                                   
 availability_365
 Min.   :  0.0   
 1st Qu.:  0.0   
 Median : 45.0   
 Mean   :112.8   
 3rd Qu.:227.0   
 Max.   :365.0   
                 
unique(ab_nyc_data$room_type)
[1] "Private room"    "Entire home/apt" "Shared room"    

Briefly describe the data

The dataset comprises 16 columns and primarily focuses on neighborhood groups and room types to determine housing prices. The price range in the dataset spans from 0 to 10000.

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.

The available room options are categorized into three types: Private room, Shared room, and Entire home/apartment.

sum(is.na(ab_nyc_data$reviews_per_month))
[1] 10052
ab_nyc_data <- ab_nyc_data %>%  replace_na(list(reviews_per_month = 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?

Upon observation, I noticed that there were 10052 rows with missing values in the “reviews_per_month” column. In order to provide potential buyers with a more accurate understanding of the reviews for the property, I decided to replace these missing values with 0.

Document your work here.

Univariate Visualizations

Let us visualize on how the prices are scattered accross the dataset.

ggplot(ab_nyc_data,aes(price))+
  geom_histogram()

airb_filt_data <- ab_nyc_data %>%
  filter(price>0 & price<2500)

ggplot(airb_filt_data,aes(price))+
  geom_histogram()

Bivariate Visualization(s)

Now, let us visualize two variables : price and room_type across the whole data.

ggplot(ab_nyc_data,aes(room_type,price))+geom_boxplot()+labs(title = "Distribution of Airbnb prices across various ranges of room types.")

Any additional comments?