java用calendr做个日历,calendR :为你定制私人专属日历

原标题:calendR :为你定制私人专属日历

01e82ada5c5b3007a89152f63a34efd6.gif

97c3d8df17edbc25a345031281741c50.png

作者 | 庄闪闪 责编 | 张文

头图 | CSDN 下载自视觉中国

来源 | 庄闪闪的成长手册(ID:Zss_R4ds)

今天教大家如何制作个人专属日历。

先说说这个包吧,非常简单,比起ggplot2 包绘制日历要简单的多。

R 中的年历图

该软件包非常易容易使用,因为它仅包含一个命名函数calendR。默认情况下,如果未指定任何参数,则该函数将以横向形式创建当年的日历,并且所有文本将使用系统的语言,如下所示:

#install.packages("calendR") #直接install安装包

library(calendR)

calendR # 默认为当前年份

3fa701b9bff9a9456459de43db2c3d42.png

如果不希望日历使用操作系统的语言,则可以对其进行修改。例如,使用英语:

Sys.setlocale("LC_ALL","English")

如果想创建其他年份的年度日历图,则可以在year 参数上设定,如下所示:

calendR(year = 2021)

1.1 日历周开始的设定

默认情况下,日历的周数将从星期日开始。设定参数start="M"可以获得从星期一开始日历图。

calendR(year = 2021, start= "M")

83047d9b1dd7b772e4b042fe8c24e3a5.png

1.2 为日子增添色彩

special.days参数可以为指定的日期添加颜色,special.col 设置颜色, low.col 设置其他日期的颜色。

比如下面就是将第 9,19 等日子设置为特定时间,其颜色为淡蓝色,其他颜色设置为白色。

calendR(year = 2021,

start= "M",

special.days = c(9, 19, 56, 79, 102, # Days to color

126, 257, 300, 342),

special.col = "lightblue", # Color of the specified days

low.col = "white") # Background color of the rest of the days

7c81950e8458c29c06e7fe0471e895be.png

技巧:如果要突出日历中所有的周末,可以将 special.days 参数设置为"weekend",此快捷方式将立即为它们全部着色。

calendR(year = 2025,

start= "M",

special.days = "weekend") # Color all weekends

7893b15d0adcda347daccad7f082a740.png

为了添加多个事件,您将需要创建一个 NA 值向量,该向量的长度与相应年份的天数相同。然后将事件添加到相应的日期,你需要在special.days参数中指定。

events

# Set the corresponding eventsevents[40:45]

# Creating the calendar with a legendcalendR(year = 2025,special.days = events,special.col = c("pink", "lightblue", # Colors"lightgreen", "lightsalmon"),legend.pos = "right") # Legend to the right

70ec938d6f6341ebc13786dc9a5943df.png

R 中的月历图

年度日历前面描述的功能也可用于月度日历中。但是月度日历还可以将文本添加到每月的某几天中。

为了创建月度日历,你需要指定年份和月份。

calendR(year = 2021, month = 8)

c7c4bde383a2fd049670f76b79b9bd39.png

2.1 为日子增添色彩

与前面相同,使用special.days参数给指定日期加上颜色。

calendR(year = 2021, month = 8,special.days = c(1, 9, 12, 23, 28),special.col = "#bfe2f2",low.col = "white")

2.2 在日子里添加文字

使用月度日历图时,可以使用text参数向日期添加一些文本,并使用参数text.pos指定其位置。使用text.size和text.col参数修改文本的大小和颜色。

calendR(year = 2021, month = 8, # Year and monthstart= "M", # Start the week on Mondaytext= c("Running", "Running", # Add text (only for monthly calendars)"Class"),text.pos = c(5, 16, 25), # Days of the month where to put the textstext.size = 4.5, # Font size of the texttext.col = 4) # Color of the texts16ebed0f68a1ad1cd4c31a78c03ee783.png

2.3 添加月相

设置lunar = TRUE可以将月相添加到其日期中。lunar.col 参数设置隐藏区域的颜色,lunar.size 设置大小。

calendR(month = 2,lunar = TRUE, # Add moons to the calendarlunar.col = "gray60", # Color of the non-visible area of the moonslunar.size = 7) # Size of the moons

925192711da19ed7ddd57831df9de94d.png

学术日历

使用start_date和end_date创建学术日历。如果你想设置某个时间段(下面是 2020 年 9 月- 2021 年 5 月 31 日)的日历,非常使用科研人员,学生。请参阅以下示例:

calendR(start_date = "2020-09-01", # Custom start dateend_date = "2021-05-31", # Custom end datestart = "M", # Start the weeks on Mondaymbg.col = 4, # Color of the background of the names of the monthsmonths.col = "white", # Color text of the names of the monthsspecial.days = "weekend", # Color the weekendsspecial.col = "lightblue", # Color of the special.dayslty = 0, # Line typebg.col = "#f4f4f4", # Background colortitle = "Academic calendar 2020-2021", # Titletitle.size = 30, # Title sizeorientation = "p") # Vertical orientation

fe64cb9b145af5d411a7c7e765cb45a2.png

当然,我觉得打印出来可能效果更好用吧。这里只是给出一个简单的例子,你可以在这个基础上加上背景以及你喜欢的颜色,可以继续往下看。

私人定制

接下来,就是给日历加了背景以及根据直男审美把其他颜色进行了调整。下面给出上次大家说还不错的日历的源代码.

可以使用 pdf = TRUE 将日历进行导出(默认为 A4 格式)。可以在doc_name 参数中指定生成的 PDF 文件的名称。此外,你可以在几种纸张尺寸之间进行选择以保存日历,从"A6"到,"A0"。但是注意,可能需要微调一些字体尺寸来获得所需的输出。

如果想制作自己的日历,只需修改 img 的图片,存储的路径(默认在我的文档里)。

3.1 日历

img

c9191c643c199cc24a48d211fff87d93.png

3.2 月历

这里和日历区别最大的点就是:月历要把每个月都输出,可以使用sapply函数,把所有月份输出。前面的 invisible 指的是:不显示图片(显示的话太费事了!保存再看更快)。

最后使用paste0将字符串进行粘合(这个方法非常好用!),而这里的 i 是变化的,所以最后生成的 pdf 文件名不一样但很有规律(除了 i 不一样)。

img

e5741a8fc6dee76eb71e022c5086c93c.png

☞弃用 Cookie!

☞前端诸神大战,Vue、React 依旧笑傲江湖

☞计算机巨星陨落!图灵奖得主 Edmund Clarke 因感染“新冠”逝世

☞Github 超 20000 Star,最火开源视频库 FFmpeg 这 20 年!

☞跨平台将终结

☞曾被“劝退”的 C++ 20 正式发布!

☞Rust 2020 调查报告出炉,95%的开发者吐槽Rust难学

982eabf2289689eb007e9e3ec4732e5d.png

点分享

109035b19329e186be944421ebe6a01d.png

点点赞

19a092ec95e05e26387bb8fec850a020.png

责任编辑:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值