Description Usage Arguments Aesthetics Data Tips Cosmetic Tips Also See Examples
View source: R/stat_calendar_heatmap.R
A calendar heatmap provides context for weeks, and day of week and is a better way to visualise daily data than line charts.
1 2 |
mapping |
mapping |
data |
df |
show.legend |
logical |
inherit.aes |
logical |
na.rm |
logical |
bandwidth |
bandwidth |
... |
more functions |
date, fill.
strftime can help extract the value
of the year, week of year, and day of week from the date column. You might
need to extract the year to facet multiple years as demonstrated in the
example.
This stat uses the following transformation to obtain the x and y
coordinate to be used in the heatmap -
data$x = 1 + as.integer(strftime(data$date, "%W"))
data$y = as.integer(strftime(data$date, "%w"))
data$y[data$y == 0L] = 7
data$y = 8 - data$y
The minimalist look can be achieved by appending the
following chunk of code to the output object:
+
xlab(NULL) +
ylab(NULL) +
scale_fill_continuous(low = 'green', high = 'red') +
theme(
axis.text = element_blank(),
axis.ticks = element_blank(),
legend.position = 'none',
strip.background = element_blank(),
panel.background = element_blank(),
panel.border = element_blank()
)
ggplot_calendar_heatmap
, a
polished but less flexible alternative.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | {
library(ggplot2)
DailyData = data.frame(
DateCol = seq(
as.Date("1/01/2014", "%d/%m/%Y"),
as.Date("31/12/2015", "%d/%m/%Y"),
"days"
),
ValueCol = runif(730)
)
DailyData$Year = strftime(DailyData$DateCol, "%Y")
ggplot(
DailyData,
aes(
date = DateCol,
fill = ValueCol
)
) +
stat_calendar_heatmap() +
facet_wrap(~Year, ncol = 1)}
|
Loading required package: ggplot2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.