-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.R
executable file
·60 lines (54 loc) · 1.99 KB
/
gen.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env Rscript
# Load packages
library(ggplot2)
library(Cairo)
library(showtext)
require(grid)
require(scales)
require(knitr)
# Global settings for knitr
## Theme
theme_pandoc <- function(base_size = 12) {
background_color="#FCFCFC"
font_color="#0077AA"
asis_color="#708090"
theme(plot.background = element_rect(fill=background_color, colour=background_color),
title = element_text(colour = font_color, size = 25),
axis.text = element_text(colour = asis_color, size = 25),
axis.text.x = element_text(size = 18, colour = font_color),
axis.title = element_blank(),
axis.line = element_line(colour = font_color),
axis.ticks = element_line(colour = font_color),
panel.margin = unit(0, "cm"),
panel.background = element_rect(fill = background_color, colour = background_color),
panel.grid.major.x = element_line(colour = font_color, linetype = "dashed"),
panel.grid.major.y = element_blank(),
panel.grid.minor.x = element_line(colour = font_color, linetype = "dashed"),
panel.grid.minor.y = element_blank()
)
}
## Figure prefix as 'fig-'
opts_knit$set(unnamed.chunk.label = 'fig')
## Do not show the code and result on the page
opts_chunk$set(echo = FALSE, results = 'hide', fig.cap = '')
## Create utf8 hook to produce figure including UTF-8 encoding
## Powered by Cairo and showtext
knit_hooks$set(utf8 = function(before, options, envir){
if(before)
{
figure_name <<- fig_path('', options)
CairoPNG(figure_name, width=1400)
showtext.begin()
}
else
{
#dev.off(); #Not work, so I move it back to the end of chunk code in Rmd file
ext = options$fig.ext
file.rename(figure_name, paste(figure_name, ".", ext, sep = ""))
}
})
# Generate HTML document
knit("analysis.Rmd")
system("pandoc analysis.md -o analysis.html --template template/pandoc --self-contained --toc")
knit("README.Rmd")
system("pandoc README.md -o README.html --template template/pandoc --toc")