library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.4     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   2.0.1     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(dplyr)
library(p8105.datasets)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout

barplot

data("rest_inspec")
rest_inspec = 
rest_inspec %>% 
    select(boro,street ,inspection_type,building, score) %>% 
    drop_na() %>% 
    filter(
    boro== "MANHATTAN",
    inspection_type == "Cycle Inspection / Initial Inspection",
    score %in% 35:45
   )
   

rest_inspec %>% 
  count(street) %>% 
  mutate(street = fct_reorder(street, n)) %>% 
  plot_ly(x = ~street, y = ~n, color = ~street, type = "bar", colors = "viridis")

boxplot

rest_inspec %>% 
  mutate(street = fct_reorder(street, score)) %>% 
  plot_ly(y = ~score, color = ~street, type = "box", colors = "viridis")

density plot

density_ggplot = 
  rest_inspec %>%
  
    select(boro,street ,inspection_type, building,score) %>% 
  drop_na() %>% 
    filter(
    boro== "MANHATTAN",
    inspection_type == "Cycle Inspection / Initial Inspection",
    score %in% 35:45,
    building %in% 0:2000
   ) %>%
  filter( 
    street %in% c(
    "10 AVENUE", 
    "7 AVENUE",
    "8 AVENUE",
    "WEST 35 STREET",
    "W 32ND ST",
    "BROADWAY",
    "west 34th st", 
    "5 AVENUE", 
    "7 AVENUE",
    "8TH AVE",
    "9 AVENUE"
   
)) %>% 
  ggplot(aes(x = street, fill = building ),colors = "viridis") +
  geom_density(alpha = 0.25) 


ggplotly(density_ggplot)