ggplot2でカレンダーを作っています。カレンダーを次のように表示したいと思います。
library(tidyverse)
library(lubridate)
library(ggforce)
datedb <- tibble(date = seq(as.Date("2021-09-01"),
as.Date("2021-12-31"), by = 1),
day = day(date),
week_no = epiweek(date),
Month = month(date, label = TRUE, abbr = FALSE),
Wday = wday(date, label = TRUE, abbr = TRUE))
ggplot(datedb, aes(Wday, week_no)) +
geom_tile(color = "black", fill = NA) +
geom_text(aes(label = day), size = 3) +
scale_y_reverse() +
scale_x_discrete(position = "top") +
facet_wrap(~ Month, ncol = 1, scales = "free",
strip.position = "top") +
theme_void() +
theme(axis.text.x = element_text(size = 9),
strip.placement = "outside",
strip.text = element_text(size = 13))
ただし、10 月のタイルが他の月よりも小さいことに気付きました。10 月は、他の月よりも 1 行多い日です。すべてのセルを同じサイズにしたいと思います。これを行う代わりにfacet_col
引数 inを使用できます:
... しかし、重要な x 軸のラベル (下の画像を参照) が失われます。月ごとに曜日を表示したいと考えています。ggforce
facet_wrap
ggforce::facet_col(vars(Month), scales = "free_y", space = "free") +
グリッド セルとx 軸ラベルを同じサイズに保つ「簡単な」ソリューションはありますか?