欢迎访问我的R Podcast!!!

欢迎访问我的R Podcast!!!

折腾了一下午终于用 blogdown 搭建了一个基于 R 的播客。欢迎访问:rblog。仅仅是想用这个博客展示一些 R 笔记,特别是有一些基于 JS 的 R 包,使用 RMarkdown 能够直接展示交互式图表。

预览:


具体的搭建方法就不再赘述了,可以参考官方的文档。因为我选择的这个主题功能很少,所以我对其进行了一些修改,参考文档如下:

Hugo中添加代码高亮支持

添加代码高亮支持:

1
2
3
4
5
6
7
8
9
10
<link href="https://cdn.bootcss.com/highlight.js/9.12.0/styles/monokai.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>

<script src="https://cdn.bootcss.com/highlight.js/9.12.0/languages/django.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.12.0/languages/dockerfile.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.12.0/languages/vim.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.12.0/languages/yaml.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.12.0/languages/gradle.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.12.0/languages/tex.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

添加 Latex 公式支持:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<script src="https://cdn.jsdelivr.net/npm/[email protected]/unpacked/MathJax.js?config=TeX-MML-AM_CHTML" defer></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
MathJax.Hub.Config({
'HTML-CSS': {
matchFontHeight: false
},
SVG: {
matchFontHeight: false
},
CommonHTML: {
matchFontHeight: false
},
tex2jax: {
inlineMath: [
['$','$'],
['\\(','\\)']
]
}
});
});
</script>

最后还是关于R绘图的中文问题,虽然直接使用电脑上安装的字体可行,不过我用Jupyter和blogdown运行的时候还是会报错,最后发现如果你在你的 .Rprofile 中添加如下代码就可以纠正错误了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
+ suppressMessages(suppressWarnings(library(showtext)))
+ suppressMessages(suppressWarnings(showtext_auto(enable = TRUE)))
+ suppressMessages(suppressWarnings(font_add(regular = '/Library/Fonts/Songti.ttc', family = "cnfont")))
+ suppressMessages(suppressWarnings(font_add(regular = '/Users/czx/Library/Fonts/RobotoSlab-Regular.ttf', family = "enfont")))
+ print("中文字体:cnfont;英文字体:enfont")
suppressMessages(suppressWarnings((Sys.setlocale("LC_TIME", "en_US.UTF-8"))))
print("已把日期环境设置成英文!")
# 加载包
suppressMessages(suppressWarnings(library(ggplot2, quietly = T)))
suppressMessages(suppressWarnings(library(dplyr, quietly = T)))
suppressMessages(suppressWarnings(library(RColorBrewer, quietly = T)))
suppressMessages(suppressWarnings(library(reshape2, quietly = T)))
suppressMessages(suppressWarnings(library(hrbrthemes)))
print("已加载ggplot2、reshape2、dplyr、hrbrthemes和RColorBrewer!")
- theme_set(theme_ipsum(base_family = 'STSong'))
+ theme_set(theme_ipsum(base_family = 'cnfont'))
print("已ggplot2绘图主题为theme_ipsum()!")
+ options(blogdown.ext = ".Rmd", blogdown.author = "程振兴")
# R

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×