streamgraph added
This commit is contained in:
parent
998979918f
commit
626dc8f24d
@ -1,5 +1,6 @@
|
|||||||
|
# dataset: https://www.kaggle.com/aiaiaidavid/airplane-crash-fatalities-since-1908-dv-03032020
|
||||||
# setup srodowiska ####
|
# setup srodowiska ####
|
||||||
install.packages('shinyjs')
|
setwd('/Users/patrycjalazna/Desktop/wizualizacja-danych/projekt_3/')
|
||||||
|
|
||||||
# importy ####
|
# importy ####
|
||||||
library(shiny)
|
library(shiny)
|
||||||
@ -57,20 +58,9 @@ airplane_crashes$btwn_6PM_6AM <- if_else
|
|||||||
|
|
||||||
|
|
||||||
# ShinyApp ####
|
# ShinyApp ####
|
||||||
load_data <- function() {
|
|
||||||
Sys.sleep(2)
|
|
||||||
hide("loading_page")
|
|
||||||
show("main_content")
|
|
||||||
}
|
|
||||||
|
|
||||||
ui <- fluidPage(
|
ui <- fluidPage(
|
||||||
useShinyjs(),
|
|
||||||
div(
|
|
||||||
id = "loading_page",
|
|
||||||
h1("Loading...")
|
|
||||||
),
|
|
||||||
hidden(
|
|
||||||
div(
|
|
||||||
id = "main_content",
|
id = "main_content",
|
||||||
navbarPage("Airplane crashes from 1908 to 2020",
|
navbarPage("Airplane crashes from 1908 to 2020",
|
||||||
tabPanel("General overview",
|
tabPanel("General overview",
|
||||||
@ -91,6 +81,12 @@ ui <- fluidPage(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
tabPanel("Streamgraph",
|
||||||
|
mainPanel(
|
||||||
|
streamgraphOutput("operatorCrashes")
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
tabPanel("Map",
|
tabPanel("Map",
|
||||||
mainPanel(
|
mainPanel(
|
||||||
# mapy
|
# mapy
|
||||||
@ -110,11 +106,9 @@ ui <- fluidPage(
|
|||||||
))
|
))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
server <- function(input, output, session) {
|
server <- function(input, output, session) {
|
||||||
load_data()
|
|
||||||
# godzina
|
# godzina
|
||||||
observe(print(strftime(input$time, "%R")))
|
observe(print(strftime(input$time, "%R")))
|
||||||
|
|
||||||
@ -147,6 +141,32 @@ server <- function(input, output, session) {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
output$operatorCrashes <- renderStreamgraph({
|
||||||
|
|
||||||
|
main_type_wise_year <- airplane_crashes %>%
|
||||||
|
select(Year, Type) %>%
|
||||||
|
# replace model number by empty strings
|
||||||
|
mutate(main_type = str_replace_all(Type, "[A-Za-z]*-?\\d+-?[A-Za-z]*.*", "")) %>%
|
||||||
|
# skip empty strings row
|
||||||
|
filter(main_type > 'A') %>%
|
||||||
|
group_by(Year, main_type) %>%
|
||||||
|
summarize(n = n()) %>%
|
||||||
|
group_by(Year) %>%
|
||||||
|
top_n(5, n)
|
||||||
|
|
||||||
|
# i teraz z tego streamgraph
|
||||||
|
main_type_wise_year <- main_type_wise_year %>% arrange(-n)
|
||||||
|
streamgraph <- main_type_wise_year %>%
|
||||||
|
group_by(Year, main_type) %>%
|
||||||
|
tally(wt=n) %>%
|
||||||
|
streamgraph("main_type", "n", "Year", interpolate="cardinal") %>%
|
||||||
|
sg_fill_brewer("PuOr") %>%
|
||||||
|
sg_legend(TRUE)
|
||||||
|
|
||||||
|
streamgraph
|
||||||
|
})
|
||||||
|
|
||||||
output$mapPlot <- renderPlotly({
|
output$mapPlot <- renderPlotly({
|
||||||
|
|
||||||
states_list <- c('Alabama','Alaska','Alaksa','Arizona','Arkansas',"California",
|
states_list <- c('Alabama','Alaska','Alaksa','Arizona','Arkansas',"California",
|
||||||
@ -247,3 +267,45 @@ server <- function(input, output, session) {
|
|||||||
|
|
||||||
shinyApp(ui = ui, server = server)
|
shinyApp(ui = ui, server = server)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# tutaj sb rysuje wykresiki demo, zeby nie odpalac shiny za kazdym razem ####
|
||||||
|
|
||||||
|
# number of fatal accidents by operator - top 5
|
||||||
|
|
||||||
|
##
|
||||||
|
# extract and group by manufacturer
|
||||||
|
# main_type_wise_year <- airplane_crashes %>%
|
||||||
|
# select(Year, Type) %>%
|
||||||
|
# # replace model number by empty strings
|
||||||
|
# mutate(main_type = str_replace_all(Type, "[A-Za-z]*-?\\d+-?[A-Za-z]*.*", "")) %>%
|
||||||
|
# # skip empty strings row
|
||||||
|
# filter(main_type > 'A') %>%
|
||||||
|
# group_by(Year, main_type) %>%
|
||||||
|
# summarize(n = n()) %>%
|
||||||
|
# group_by(Year) %>%
|
||||||
|
# top_n(5, n)
|
||||||
|
# #%>% mutate(main_type = reorder_within(-n, main_type, Year))
|
||||||
|
#
|
||||||
|
# # i teraz z tego streamgraph
|
||||||
|
# main_type_wise_year <- main_type_wise_year %>% arrange(-n)
|
||||||
|
# main_type_wise_year %>%
|
||||||
|
# group_by(Year, main_type) %>%
|
||||||
|
# tally(wt=n) %>%
|
||||||
|
# streamgraph("main_type", "n", "Year", interpolate="cardinal") %>%
|
||||||
|
# sg_fill_brewer("PuOr") %>%
|
||||||
|
# sg_legend(TRUE)
|
||||||
|
|
||||||
|
####
|
||||||
|
# airplane_operators <- airplane_crashes %>% count(Operator, sort = TRUE)
|
||||||
|
# airplane_operators <- head(airplane_operators, 5)
|
||||||
|
# ggplot(airplane_operators, aes(x = Operator, y = n)) +
|
||||||
|
# geom_point(color = "#765432", alpha = 0.8) +
|
||||||
|
# labs(title = "No. of fatal accidents by operator", x = '', y = '')
|
||||||
|
#
|
||||||
|
# airplane_operators %>%
|
||||||
|
# streamgraph(key="Operator", value=, date="Year", offset="zero") %>%
|
||||||
|
# sg_fill_brewer("BuPu")
|
||||||
|
|
||||||
|
# wykres ile wypadkow kazdego operatora w kazdym roku
|
||||||
|
Loading…
Reference in New Issue
Block a user