Skip to content

Instantly share code, notes, and snippets.

@TonyLadson
Created August 28, 2016 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TonyLadson/4f355e4a299101483123f031c6fc68d6 to your computer and use it in GitHub Desktop.
Save TonyLadson/4f355e4a299101483123f031c6fc68d6 to your computer and use it in GitHub Desktop.
Storm occurrence by day of the week
library(ggplot2)
library(dplyr)
library(lubridate)
library(cowplot)
# Storms on days of the week
# Storm archive
# http://www.bom.gov.au/australia/stormarchive/
# Victoria
# 1 Jan 2010 to present
# Read in the dates of storms. This data was downloaded from the website.
storms <-
c("17/06/2010 3:00", "17/01/2010 15:30", "31/01/2010 3:10", "4/02/2010 5:00",
"4/02/2010 5:00", "9/02/2010 8:00", "10/02/2010 2:00", "10/02/2010 2:25",
"10/02/2010 4:50", "10/02/2010 5:00", "10/02/2010 6:00", "11/02/2010 5:00",
"26/02/2010 4:00", "6/03/2010 2:30", "6/03/2010 3:15", "6/03/2010 3:30",
"6/03/2010 3:25", "6/03/2010 3:50", "6/03/2010 6:13", "6/03/2010 8:00",
"7/03/2010 5:50", "7/03/2010 6:04", "7/03/2010 6:00", "7/03/2010 8:00",
"20/04/2010 5:00", "20/04/2010 5:00", "7/03/2010 7:30", "6/03/2010 3:05",
"6/03/2010 4:00", "6/03/2010 4:30", "6/03/2010 4:00", "6/03/2010 4:00",
"6/03/2010 4:15", "6/03/2010 4:10", "6/03/2010 3:30", "6/03/2010 3:30",
"6/03/2010 4:18", "6/03/2010 3:30", "6/03/2010 2:00", "6/03/2010 4:30",
"6/03/2010 3:40", "6/03/2010 2:00", "6/03/2010 4:30", "6/03/2010 4:30",
"6/03/2010 3:16", "6/03/2010 3:15", "6/03/2010 4:10", "18/08/2010 11:00",
"18/08/2010 11:00", "9/09/2010 6:45", "12/10/2010 5:35", "12/10/2010 5:00",
"13/11/2010 8:15", "26/11/2010 4:20", "26/11/2010 3:40", "26/11/2010 5:35",
"26/11/2010 8:05", "26/11/2010 5:00", "3/02/2011 7:20", "3/02/2011 7:30",
"3/02/2011 10:00", "3/02/2011 10:00", "3/02/2011 10:00", "3/02/2011 10:00",
"16/02/2011 5:40", "4/02/2011 1:45", "4/02/2011 2:05", "4/02/2011 1:42",
"4/02/2011 4:06", "4/02/2011 5:00", "4/02/2011 6:10", "4/02/2011 7:45",
"4/02/2011 6:50", "4/02/2011 6:50", "4/02/2011 7:15", "4/02/2011 8:30",
"4/02/2011 8:10", "4/02/2011 8:00", "4/02/2011 11:00", "6/10/2010 6:45",
"7/11/2010 11:00", "12/11/2010 7:05", "12/11/2010 8:05", "24/11/2010 3:00",
"24/11/2010 6:30", "25/11/2010 2:50", "1/12/2010 5:45", "1/12/2010 5:04",
"1/12/2010 5:45", "1/12/2010 5:00", "2/12/2010 3:00", "2/12/2010 4:40",
"2/12/2010 4:00", "3/12/2010 5:55", "3/12/2010 7:00", "3/12/2010 3:00",
"3/12/2010 2:36", "4/12/2010 5:30", "5/12/2010 1:30", "5/12/2010 1:55",
"5/12/2010 5:15", "6/12/2010 4:00", "17/12/2010 7:00", "10/01/2011 6:45",
"22/01/2011 8:00", "12/01/2011 9:20", "4/02/2011 6:40", "13/03/2011 4:50",
"25/11/2010 7:42", "3/12/2010 0:00", "3/12/2010 4:00", "4/02/2011 7:40",
"13/03/2011 4:40", "13/03/2011 4:15", "28/09/2011 5:30", "28/09/2011 5:40",
"6/10/2011 4:30", "6/10/2011 8:30", "22/10/2011 4:10", "22/10/2011 6:00",
"28/10/2011 5:45", "9/11/2011 7:50", "9/11/2011 8:00", "9/11/2011 8:00",
"9/11/2011 8:00", "9/11/2011 8:15", "9/11/2011 3:00", "25/11/2011 10:30",
"10/12/2011 6:00", "16/12/2011 6:45", "25/11/2011 23:45", "25/11/2011 23:50",
"18/12/2011 5:15", "18/12/2011 6:00", "18/12/2011 5:00", "18/12/2011 7:30",
"18/12/2011 5:40", "18/12/2011 6:28", "18/12/2011 6:40", "19/12/2011 0:00",
"18/12/2011 11:00", "18/12/2011 6:30", "18/12/2011 11:25", "18/12/2011 12:40",
"24/12/2011 5:00", "25/12/2011 4:30", "25/12/2011 6:10", "25/12/2011 6:30",
"25/12/2011 5:30", "25/12/2011 4:53", "4/12/2010 11:00", "9/02/2012 9:30",
"9/02/2012 3:00", "9/02/2012 7:15", "28/01/2012 9:50", "10/02/2012 2:30",
"10/02/2012 4:35", "10/02/2012 6:30", "20/12/2012 0:00", "19/02/2012 23:30",
"19/02/2012 23:30", "26/02/2012 6:00", "27/02/2012 4:41", "27/02/2012 4:40",
"27/02/2012 6:00", "27/02/2012 9:30", "27/02/2012 8:00", "27/02/2012 8:30",
"27/02/2012 8:30", "14/03/2012 4:30", "22/04/2012 8:15", "22/02/2012 5:30",
"24/04/2012 1:00", "9/11/2011 8:30", "17/12/2011 19:00", "14/02/2013 16:00",
"14/02/2013 15:00", "14/02/2013 6:00", "26/02/2013 14:00", "27/02/2013 16:00",
"27/02/2013 19:00", "22/10/2013 7:20", "15/01/2014 7:05", "16/01/2014 9:40",
"19/02/2014 7:05", "15/03/2014 12:30", "15/03/2014 8:05", "21/03/2014 3:00",
"21/03/2014 6:15", "21/03/2014 5:50", "21/03/2014 7:30", "27/03/2014 7:00",
"9/09/2014 4:25", "9/09/2014 3:30", "1/12/2014 0:00", "3/12/2014 6:00",
"5/12/2014 7:00", "6/12/2014 4:00", "6/12/2014 4:00", "6/12/2014 4:00",
"7/12/2014 4:00", "3/01/2015 6:00", "7/01/2015 6:20", "7/01/2015 10:08",
"7/01/2015 10:08", "9/01/2015 8:00", "9/01/2015 8:00", "9/01/2015 8:00",
"9/01/2015 8:00", "9/01/2015 8:00", "9/01/2015 8:00", "21/01/2015 7:00",
"17/02/2015 4:30", "23/02/2015 7:00", "5/12/2014 8:40", "6/12/2014 2:30",
"13/02/2015 6:30", "11/10/2015 6:30", "10/10/2015 8:15", "1/11/2015 3:50",
"4/11/2015 7:00", "5/11/2015 2:15", "5/11/2015 3:15", "5/11/2015 2:30",
"12/11/2015 4:00", "8/12/2015 6:00", "8/12/2015 6:26", "8/12/2015 6:15",
"3/01/2016 6:13", "3/01/2016 8:00", "4/01/2016 3:30", "27/01/2016 4:00",
"27/01/2016 4:50", "28/01/2016 2:30", "28/01/2016 4:00", "31/03/2016 3:50",
"11/03/2016 20:55")
nrow(storms) # number of storms
#237
# Convert to a data frame
storms <- data_frame(storm_day = wday(parse_date_time(storms, orders = 'dmy_hm'), label = TRUE, abbr = FALSE),
day_num = wday(parse_date_time(storms, orders = 'dmy_hm'), label = FALSE))
# Add a column that has Monday (rather than Sunday) day 1
storms <- storms %>%
mutate(storm_day_monday = factor(storm_day, ordered = TRUE,
levels = c('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')))
# plot
storms %>%
ggplot(aes(storm_day_monday)) + stat_count(fill = 'blue') +
labs(x = '', y = 'Count') + theme_cowplot(font_size = 16)
day_count <- storms %>%
count(storm_day)
day_count
# # A tibble: 7 x 2
# storm_day n
# <ord> <int>
# 1 Sunday 39
# 2 Monday 13
# 3 Tuesday 14
# 4 Wednesday 39
# 5 Thursday 34
# 6 Friday 53
# 7 Saturday 45
chisq.test(day_count$n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment