-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot result.Rmd
More file actions
80 lines (67 loc) · 2.17 KB
/
plot result.Rmd
File metadata and controls
80 lines (67 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
title: "Plot_ly result"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r library, include = FALSE}
library(tidyverse)
library(p8105.datasets)
library(plotly)
library(flexdashboard)
```
```{r import data}
data("rest_inspec")
rest <- rest_inspec %>%
filter(!is.na(grade),
!is.na(score),
grade != "Not Yet Graded") %>%
select(boro, building, cuisine_description, dba, score, grade, inspection_date) %>%
rename(cuisine = cuisine_description) %>%
distinct() %>%
mutate(
cuisine = recode(cuisine,
"Ice Cream, Gelato, Yogurt, Ices" = "Ice Cream",
"Bottled beverages, including water, sodas, juices, etc." = "Bottled beverage",
"Juice, Smoothies, Fruit Salads" = "Juice",
"Latin (Cuban, Dominican, Puerto Rican, South & Central American)" = "Latin",
"Vietnamese/Cambodian/Malaysia" = "Vietnamese",
"Sandwiches/Salads/Mixed Buffet" = "Sandwiches/Salads") )
```
Column {data-width=550}
-----------------------------------------------------------------------
### Inspection Score of Restaurants Serving Different Cuisine Types
```{r fig1:cuisine type and score}
rest %>%
filter(boro == "BRONX") %>%
mutate(text_label = str_c("Cuisine: ", cuisine, "\nGrade: ", grade)) %>%
mutate(cuisine = fct_reorder(cuisine, score)) %>%
plot_ly(
y = ~score, color = ~cuisine ,
type = "box", colors = "viridis"
)
```
Column {data-width=450}
-----------------------------------------------------------------------
### Ispection Grade of Restaurant in Different Boroughs
```{r fig2: rate between boros}
rest %>%
filter(boro != "Missing") %>%
group_by(boro, grade) %>%
summarize(num = n()) %>%
plot_ly(
y = ~num, x = ~boro, color = ~grade, type = "bar"
) %>%
layout(yaxis = list(title = 'Count'), barmode = "stack")
```
### Ispection Grade Proportions in Different Boroughs
```{r fig}
rest %>%
filter(boro != "Missing") %>%
group_by(boro, grade) %>%
summarize(num = n()) %>%
mutate(all_num = sum(num)) %>%
mutate(proportion = num/all_num)%>%
plot_ly(x=~grade, y=~proportion, type = "scatter", color = ~boro, mode = "line")
```