calendR是ggplot2生态系统中的一员,其主要目的用来快速生成一个定制化的日历,可以打印输出非常漂亮,适合做规划或者项目时间管理。


# 安装
install.packages("calendR")
# 整个包非常简单,就一个函数:
calendR(
  year = format(Sys.Date(), "%Y"),
  month = NULL,
  start_date = NULL,
  end_date = NULL,
  start = c("S", "M"),
  orientation = c("portrait", "landscape"),
  title,
  title.size = 20,
  title.col = "gray30",
  subtitle = "",
  subtitle.size = 10,
  subtitle.col = "gray30",
  text = "",
  text.pos = NULL,
  text.size = 4,
  text.col = "gray30",
  special.days = NULL,
  special.col = "gray90",
  gradient = FALSE,
  low.col = "white",
  col = "gray30",
  lwd = 0.5,
  lty = 1,
  font.family = "sans",
  font.style = "plain",
  day.size = 3,
  days.col = "gray30",
  weeknames,
  weeknames.col = "gray30",
  weeknames.size = 4.5,
  months.size = 10,
  months.col = "gray30",
  months.pos = 0.5,
  mbg.col = "white",
  legend.pos = "none",
  legend.title = "",
  bg.col = "white",
  bg.img = "",
  margin = 1,
  lunar = FALSE,
  lunar.col = "gray60",
  lunar.size = 7,
  pdf = FALSE,
  doc_name = "",
  papersize = "A4"
)

一个简单的例子:


# 加载包
library(calendR)
# 个性化定制日历
calendR(
  start_date = "2021-01-01",  # 起始时间
  end_date = "2021-12-31",    # 结束时间
  start = "M",                # 以那一天作为一个月的起始,周一
  mbg.col = 4,                # 背景颜色
  months.col = "white",       # 月份字体颜色
  special.days = "weekend",   # 特殊日期
  special.col = "lightgrey",  # 特殊日期颜色显示
  lty = 0,                    # 线的样式
  bg.col = "#f4f4f4",         # 背景颜色
  title = "2021年日历",    # 标题
  title.size = 30,            # 标题字体大小
  weeknames.size = 3,         # 星期字体大小
  orientation = "p",          # 日历方向
  papersize = "A4"            # 大小
) 

参考资料:

1.https://r-coder.com/calendar-plot-r/

2.https://github.com/R-CoderDotCom/calendR