Weather radials for Canberra and Lord Howe Island made using R

Weather data was obtained for Canberra and Lord Howe Island from the Automated Surface Observing System (ASOS) https://mesonet.agron.iastate.edu/request/download.phtml?network=IN__ASOS for the time period 1 January 2016 to 29 May 2016.

The aim of this analysis was to examine the difference in temperature patterns between Canberra and Lord Howe Island in Australia and learn how to generate weather radial charts using R.

Importing data

Data was downloaded in .csv format and imported into R.

setwd('E:/OurDocs/Anna/Data_visualization/Downloaded_data')
mydata <- read.csv('asos.csv', stringsAsFactors = FALSE, header=TRUE, sep=",", na.strings="M")

Load packages

library(dplyr) #data manipulation tools
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2) #visualization - static charts
library(markdown) #reproducible reporting
library(dygraphs) #interactive time series charts (JS)
library(lubridate) #Dates and times made easy
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
library(wesanderson) #Wes Anderson palette"
library(viridis) #colour scale for radial plot
library(scales) #scale functions for graphs
library(ggthemes) #themes for ggplot2

Frequency table of number of readings for each station

YSCB = Canberra and YLHI = Lord Howe Island

#Freq table of station - LHI has more records than CBR
table(mydata$station)
## 
## YLHI YSCB 
## 8163 6662

Extract dates from datetime variable

#Extract date from datetime using substring function (extracts variables as character)
mydata$valid2 <- substr(mydata$valid, 1,10) #day, month, year
mydata$day <- substr(mydata$valid2, 1,2) #Extracts day from date
mydata$month <- substr(mydata$valid2, 4,5) #Extracts month from date
mydata$date <- as.Date(mydata$valid2, "%d/%m/%Y") #Converts character variable to date  

Convert temperature variables from degrees F to degrees C

#T(°C) = (T(°F) - 32) / 1.8
mydata$tmpc <- (mydata$tmpf - 32)/1.8
mydata$dwpc <- (mydata$dwpf - 32)/1.8

Calculate maximum and minimum temperatures and mean temperature for each day and station

mydata %>% group_by(day, month, station) %>%
  summarise(max=max(tmpc)) -> maxtmp

mydata %>% group_by(day, month, station) %>%
  summarise(min=min(tmpc)) -> mintmp

mydata %>% group_by(day, month, station) %>%
  summarise(mean=mean(tmpc)) -> meantmp

Merge data sets

tmp_data <- merge(maxtmp, mintmp, c("day","month","station"))
tmp_data2 <- merge(tmp_data, meantmp, c("day","month","station"))
mydata2 <- merge(mydata, tmp_data2, c("day","month","station"))

Filter data by station

CBR <- mydata2 %>% filter(station == "YSCB") %>% 
                    select(date, station, lon, lat, max, min, mean) %>% distinct(date)
LHI <- mydata2 %>% filter(station == "YLHI") %>% 
  select(date, station, lon, lat, max, min, mean) %>% distinct(date)

Radial plots

Source of code http://jkunst.com/r/how-to-weather-radials/. The subtitle and captions do not appear for some reason.

#Canberra - 1 Jan 2016 to 27 May 2016
ggplot(CBR, aes(date,
               ymin = min,
               ymax = max,
               color = mean)) +
geom_linerange(size = 1.3, alpha = 0.75) +
  scale_color_viridis(NULL, option = "A") +
  scale_x_date(labels = date_format("%b"), breaks = date_breaks("month")) + 
  ylim(-10, 35) +
  labs(title = "Canberra Weather Radial",
       subtitle = "1 Jan to 27 May 2016",
       caption = "Mean temperature",
       x = NULL, y = NULL) +
  coord_polar() + 
  theme_minimal() +
  theme(legend.position = "bottom")
## Warning: Removed 5 rows containing missing values (geom_linerange).

#Lord Howe Island - 1 Jan 2016 to 27 May 2016
ggplot(LHI, aes(date,
                ymin = min,
                ymax = max,
                color = mean)) +
  geom_linerange(size = 1.3, alpha = 0.75) +
  scale_color_viridis(NULL, option = "A") +
  scale_x_date(labels = date_format("%b"), breaks = date_breaks("month")) + 
  ylim(-10, 35) + 
  labs(title = "Lord Howe Island Weather Radial",
       subtitle = "1 Jan to 27 May 2016",
       caption = "Mean temperature",
       x = NULL, y = NULL) +
  coord_polar() + 
  theme_minimal() +
  theme(legend.position = "bottom")

Generate a map of Canberra and Lord Howe Island

library(leaflet)
m <- leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(lng=149.2003, lat=-35.3088, popup="Canberra, ACT, Australia") %>%
  addMarkers(lng=159.0770, lat=-31.5383, popup="Lord Howe Island, NSW, Australia")
m  # Print the map