-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dogs of New York.Rmd
150 lines (80 loc) · 3.67 KB
/
Dogs of New York.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
title: "Dog Bites in New York in 2017"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
theme: united
---
```{r setup, include = FALSE}
# This is a setup environment for setting up libraries and creating necessary data transformations
library (flexdashboard)
library (tidyverse)
library (plotly)
#Importing the dataset
datadogs2017 <- read_csv ("datadogs2017.csv")
# This is data to be used for textual part related to boroughs
datadogsborougs <- datadogs2017 %>%
group_by (borough) %>%
tally() %>%
arrange (desc (n)) %>%
mutate (perc = round ((n/sum(n)) * 100, 0))
#Dataset for datatable
datadogstable <- datadogs2017 %>%
select (-zip_code)
#Creating a subset for top three breeds for bar graph
datadogsbreed <- datadogs2017 %>%
group_by (breed) %>%
tally () %>%
rename (Number_of_bites = n) %>%
arrange (desc (Number_of_bites)) %>%
top_n(3)
# Changing order of levels to be presented on the graph properly
datadogsbreed$breed <- factor (datadogsbreed$breed,
levels = c ("Pit Bull", "Unknown", "Shih Tzu"))
# Creating subset for gender and spay/neutered for second stacked bar graph
datadogsgenderspay <- datadogs2017 %>%
group_by (spay_neuter, gender) %>%
tally () %>%
#Creating another variable that will be called Info in order to be used as a label
mutate (Info = paste ('<br>', "Spay/Neuter:",
spay_neuter, '<br>',
"Number of bites:", n, '<br>',
"Gender:", gender, '<br>'))
```
Column {data-width=650}
-----------------------------------------------------------------------
### **How much do dogs bite in New York City** {data-height=250, align=justify}
This dashboard shows statistics of dog bites in New York City in 2017. It shows that there were total of **`r nrow(datadogs2017)`** bites. The bar chart below shows which were the top three biters per breed. Although, there are certain patterns that might suggest that **Pit Bulls** are the most aggressive, it might just be the case that there are more of them in New York in comparison to other breeds. **`r datadogsborougs[1,1]`** and **`r datadogsborougs[2,1]`** are the two boroughs with the highest percentage of bites **`r datadogsborougs[1,3]`%** and **`r datadogsborougs[2,3]`%** respectively.
### **Table of Dog Bites in New York in 2017** {data-height=750}
```{r}
# Using DT package to create datatable
DT :: datatable (datadogstable, options = list(
bPaginate = TRUE))
```
Column {data-width=350}
-----------------------------------------------------------------------
### **Three breeds with the highest number of bites in 2017**
```{r}
#Barchart for breed biters using ggplot and plotly package
p <- ggplot (data = datadogsbreed, aes (x = breed, y = Number_of_bites))+
geom_col (fill = c("darkred", "darkgreen", "darkblue")) +
ylab ("Number of Bites") +
theme (legend.position = "none",
panel.background = element_rect (fill = "lightcyan"))
# Turn it interactive with ggplotly
p <- ggplotly (p)
p
```
### **Bites based on dog's gender and whether they were spayed/neutered** {align=center}
```{r}
#Creating stacked bar using ggplot and plotly package
p1<- ggplot (data = datadogsgenderspay)+
geom_col (aes (x = spay_neuter, y = n, fill = gender, label = Info)) +
scale_fill_manual (values = c('cyan3', 'darkorange', "purple")) +
ylab ("Number of bites") +
theme (legend.position = "none",
panel.background = element_blank())
p1<-ggplotly(p1,tooltip = "Info")
p1
```