Mini lesson 9 Tin Le Hourly heatmap and add_cat() ## Loading packages and data
library(ggplot2)
library(dplyr)
##
## 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(viridis)
## Loading required package: viridisLite
library(Interpol.T) # will generate a large dataset on initial load
## Loading required package: date
## Loading required package: chron
library(lubridate) # for easy date manipulation
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:chron':
##
## days, hours, minutes, seconds, years
## The following object is masked from 'package:base':
##
## date
library(ggExtra) #ggplot themes
library(tidyr)
library(rlang)
hdata<- data(Trentino_hourly_T,package = "Interpol.T")
names(h_d_t)[1:5]<- c("stationid","date","hour","temp","flag")
df<- tbl_df(h_d_t) %>%
filter(stationid == "T0001") #one data set
df<- df %>% mutate(year = year(date),
month = month(date, label=TRUE),
day = day(date))
#cleaning up objects that are not needed
rm(list=c("h_d_t","mo_bias","Tn","Tx",
"Th_int_list","calibration_l",
"calibration_shape","Tm_list"))
statno = unique(df$stationid) #unique returns a vector, data frame or array like x but with duplicate elements/rows removed.
hmap = ggplot(df, aes(day, hour, fill = temp)) +
geom_tile(color = "white", size = 0.1) +
scale_fill_viridis(name = "Hrly Temps C", option = "C")
hmap = hmap + facet_grid(year~month) +
scale_y_continuous(trans = "reverse", breaks = unique(df$hour)) +
theme_minimal(base_size = 8) +
labs(title = paste("Hourly Temps - Station", statno), x = "Day", y = "Hour Commencing") +
theme(plot.title = element_text(size = 14),
axis.text.y = element_text(size = 6),
strip.background = element_rect(colour = "white"),
axis.ticks = element_blank(),
axis.text = element_text(size = 9),
legend.title = element_text(size = 8),
legend.text = element_text(size = 6))
hmap
Source: https://www.r-graph-gallery.com/283-the-hourly-heatmap/
library(ggplot2)
library(devtools)
## Loading required package: usethis
this_base = "0002_add-background-with-cats-package"
#devtools::install_github("hilaryparker/cats")
library(cats)
#library(help = "cats")
cats = ggplot(mpg, aes(cty, hwy)) +
add_cat() +
geom_point()
cats
cats2 = ggplot(mpg, aes(cty, hwy)) +
add_cat() +
geom_point()
cats2
cats3 = ggplot(mpg, aes(cty, hwy)) +
add_cat() +
geom_point()
cats3
cats4 = ggplot(mpg, aes(cty, hwy)) +
add_cat() +
geom_point()
cats4