diff --git a/proj3/projekt.R b/proj3/projekt.R index 80e1190..e76b2be 100644 --- a/proj3/projekt.R +++ b/proj3/projekt.R @@ -77,7 +77,8 @@ ui <- fluidPage( mainPanel( # wykresiki plotlyOutput("weekdayCrashes"), - plotlyOutput("hourCrashes") + plotlyOutput("hourCrashes"), + plotlyOutput("monthCrashes") ) ) ), @@ -174,8 +175,36 @@ server <- function(input, output, session) { }) - - + output$monthCrashes <- renderPlotly({ + + crashes_per_months <- airplane_crashes %>% count(Month) + + crashes_per_months$Month <- as.character(crashes_per_months$Month) + + crashes_per_months$Month[crashes_per_months$Month == 1] <- "January" + crashes_per_months$Month[crashes_per_months$Month == 2] <- "February" + crashes_per_months$Month[crashes_per_months$Month == 3] <- "March" + crashes_per_months$Month[crashes_per_months$Month == 4] <- "April" + crashes_per_months$Month[crashes_per_months$Month == 5] <- "May" + crashes_per_months$Month[crashes_per_months$Month == 6] <- "June" + crashes_per_months$Month[crashes_per_months$Month == 7] <- "July" + crashes_per_months$Month[crashes_per_months$Month == 8] <- "August" + crashes_per_months$Month[crashes_per_months$Month == 9] <- "September" + crashes_per_months$Month[crashes_per_months$Month == 10] <- "October" + crashes_per_months$Month[crashes_per_months$Month == 11] <- "November" + crashes_per_months$Month[crashes_per_months$Month == 12] <- "December" + + + df <- crashes_per_months + df <- df %>% arrange(match(Month, c("January", "February","March", "April", "May", "June", "July", "August", "September", "October", "November", "December"))) + fig <- df %>% plot_ly(labels = ~Month, values = ~n, sort=FALSE) + fig <- fig %>% add_pie(hole = 0.4) + fig <- fig %>% layout(title = "No. of crashes per month", xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE), + yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE)) + + fig + + }) output$operatorCrashes <- renderStreamgraph({