added barplot (no of crashes per year)

This commit is contained in:
patrycjalazna 2021-06-23 17:46:00 +02:00
parent 6d891c2d02
commit cc56a22899
2 changed files with 52 additions and 17 deletions

View File

@ -92,11 +92,14 @@ ui <- fluidPage(
min(airplane_crashes$Date),
max(airplane_crashes$Date)),
# wybor godziny
timeInput("time", "Time (local):", seconds = FALSE)),
column(6, plotlyOutput("weekdayCrashes"))
timeInput("time", "Time (local):", seconds = FALSE)
),
column(6, plotOutput("crashes_each_year"))
),
fixedRow(
column(3, plotlyOutput("hourCrashes")),
column(3, plotlyOutput("weekdayCrashes")),
column(3, plotlyOutput("monthCrashes"))
)),
tabPanel("Streamgraph",
@ -132,10 +135,23 @@ server <- function(input, output, session) {
# godzina
observe(print(strftime(input$time, "%R")))
output$crashes_each_year <- renderPlot({
year_wise <- airplane_crashes %>% count(Year)
year_wise <- year_wise %>%
filter(Year > year(input$dates[1])) %>%
filter(Year < year(input$dates[2]))
ggplot(year_wise, aes(x = Year, y = n)) +
geom_col(fill = '#0f4c75', col = 'white') +
labs(title = 'No. of Airplane crashes since 1908 each year', x = '', y = '') +
scale_x_continuous(breaks = seq(1908, 2020, 4))
})
output$weekdayCrashes <- renderPlotly({
week_day <- airplane_crashes %>% count(Weekday)
week_day$Weekday <- as.character(week_day$Weekday)
week_day$Weekday[week_day$Weekday == 1] <- "Monday"
@ -149,15 +165,36 @@ server <- function(input, output, session) {
# zmiana kolejnosci dni; dni nie powinny sie wyswietlac alfabetycznie
week_day$Weekday <- factor(week_day$Weekday, levels= c('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'))
plot_ly(
x = week_day$Weekday, y = week_day$n,
name = 'No. of crashes per week day', type = "bar"
) %>%
layout(title = 'Week Day Crashes',
xaxis = list(title = "Weekdays",
zeroline = FALSE),
yaxis = list(title = "No. of crashes",
zeroline = FALSE))
# plot_ly(
# x = week_day$Weekday, y = week_day$n,
# name = 'No. of crashes per week day', type = "bar"
# ) %>%
# layout(title = 'Week Day Crashes',
# xaxis = list(title = "Weekdays",
# zeroline = FALSE),
# yaxis = list(title = "No. of crashes",
# zeroline = FALSE))
df <- week_day
df <- df %>% arrange(Weekday)
fig <- df %>% plot_ly(labels = ~Weekday, values = ~n, sort=FALSE)
fig <- fig %>% add_pie(hole = 0.4)
fig <- fig %>% layout(title = "No. of crashes per weekday", xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
fig
#
# df <- df %>% arrange(Hour)
# df$Hour <- as.character(df$Hour)
# df$Hour <- paste(df$Hour, ":00", sep = "")
# fig <- df %>% plot_ly(labels = ~Hour, values = ~n, sort=FALSE)
# fig <- fig %>% add_pie(hole = 0.4)
# fig <- fig %>% layout(title = "No. of crashes per hour", xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
# yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
#
# fig
})
@ -193,8 +230,6 @@ server <- function(input, output, session) {
fig
})
output$monthCrashes <- renderPlotly({

BIN
proj3/www/crashed_plane.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 KiB