forked from codigourbano/ocorrencias-transito-pmsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
presentation.Rpres
44 lines (33 loc) · 1.35 KB
/
presentation.Rpres
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
Traffic Accidents in São Paulo - 2015 dataset
========================================================
author: Wagner Pinheiro
date: February, 2017
autosize: true
Collisions vs Run Over - 2015
========================================================
```{r, echo=F}
# load packages
# install.packages(c("tidyr","dplyr","ggplot2","plotly", "webshot"))
# info: https://github.com/DataScienceSpecialization/Developing_Data_Products/blob/master/plotly/plotly.Rmd
t <- Sys.setlocale(locale = "en_US.UTF-8")
suppressPackageStartupMessages(library(plotly))
suppressPackageStartupMessages(library(tidyr))
suppressPackageStartupMessages(library(dplyr))
source("main.R")
dataset <- TrafficAccidents.loadDataset()
# str(dataset)
# head(dataset)
dataset <- dataset %>%
mutate(month = factor(months.Date(DATE), levels=month.name)) %>%
mutate(type = factor(ifelse(COD_ACID==4, "Run over by vehicle","Collisions")))
dataset <- dataset %>%
group_by(month, type) %>%
summarise(deaths = sum(VITIMAS_MORTE))
# dataset <- as.data.frame(dataset) %>%
# gather(month)
total <- sum(dataset$deaths)
p <- plot_ly(dataset, x = ~month, y = ~deaths, split=~type, type = "bar") %>%
layout(title = paste(total, " Deaths by Month and Type in Traffic - 2015"), yaxis = list(title = 'Deaths'), barmode = 'stack')
chart_link = plotly_POST(p, filename="traffic_accidents_by_type")
chart_link
```