-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.Rmd
59 lines (47 loc) · 1.39 KB
/
dashboard.Rmd
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
---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
# examples of plotly
library(p8105.datasets)
library(tidyverse)
library(plotly)
data("nyc_airbnb")
nyc_airbnb <-
nyc_airbnb %>%
mutate(rating = review_scores_location/2) %>%
select(neighbourhood_group, neighbourhood, rating, price, room_type, lat, long) %>%
filter(neighbourhood_group == "Manhattan",
price %in% 100:500,
room_type == "Entire home/apt") %>%
drop_na(rating)
```
# examples of plotly
Column {data-width=650}
-----------------------------------------------------------------------
## scatterplot
```{r}
nyc_airbnb %>%
mutate(text_label = str_c("Price $", price, "\nRating", rating)) %>%
plot_ly(x = ~lat, y = ~ long, type = "scatter", mode = "markers", color = ~ price, alpha = 0.5, text = ~ text_label)
```
Column {data-width=350}
-----------------------------------------------------------------------
## boxplot
```{r}
nyc_airbnb %>%
plot_ly(y = ~ price, x = ~ neighbourhood, type = "box", colors = "viridis", color = ~neighbourhood)
```
## bar plot
```{r}
nyc_airbnb %>%
count(neighbourhood) %>%
mutate(neighbourhood = fct_reorder(neighbourhood, n)) %>%
plot_ly(x = ~ neighbourhood, y = ~ n, color = ~ neighbourhood, type = "bar", colors = "viridis")
```