-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.Rmd
192 lines (132 loc) · 4.11 KB
/
test.Rmd
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
---
title: "R for bioinformatics, data summarisation and statistics"
subtitle: "HUST Bioinformatics course series"
author: "Wei-Hua Chen (CC BY-NC 4.0)"
institute: "HUST, China"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
beamer_presentation:
theme: AnnArbor
colortheme: beaver
fonttheme: structurebold
highlight: tango
slide_level: 2
toc: true
includes:
in_header: mystyle.sty
---
```{r include=FALSE}
color_block = function(color) {
function(x, options) sprintf('\\color{%s}\\begin{verbatim}%s\\end{verbatim}',
color, x)
}
## 将错误信息用红色字体显示
knitr::knit_hooks$set(error = color_block('red'))
```
# section 1: TOC
## 前情提要
## 本次提要
# section 2: XX
## some page with layout
Column 1
--------------------------------------------------
### Chart A
```{r}
```
Column 2
--------------------------------------------------
### Chart B
```{r}
```
### Chart C
```{r}
```
# section 3: XX
# section 5: 小结及作业!
## 本次小结
### XXX
### 相关包
## 公式中的写法之**代数符号**
\FontSmall
|分类| R的表达式 | 显示结果 |
|---------------------|-------------------------|----|
|代数符号| ```expression(x + y)``` | $x + y$ |
||```expression(x - y)```| $x-y$ |
||```expression(x * y)```|$xy$|
||```expression(x / y)```| $x/y$ |
||```expression(x %+-% y)```| $x \pm y$ |
||```expression(x %/% y)```| $x \div y$ |
||```expression(x %*% y)```| $x \times y$ |
||```expression(x %.% y)```|$x \cdot y$|
|| ```expression(x[i])``` | $x_{i}$ |
|| ```expression(x^2)``` | $x^{2}$ |
||```expression(sqrt(x))```| $\sqrt{x}$ |
||```expression(sqrt(x,y))```| $\sqrt[y]{x}$ |
||```expression(list(x,yz))```| $x,y,z$ |
## 希腊字符
代码
\FontSmall
```{r}
library(ggplot2);
greeks <- c("Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta",
"Eta", "Theta", "Iota", "Kappa", "Lambda", "Mu",
"Nu", "Xi", "Omicron", "Pi", "Rho", "Sigma",
"Tau", "Upsilon", "Phi", "Chi", "Psi", "Omega");
dat <- data.frame( x = rep( 1:6, 4 ), y = rep( 4:1, each = 6), greek = greeks );
plot2 <-
ggplot( dat, aes(x=x,y=y) ) + geom_point(size = 0) +
# 画希腊字符,注意下面两行代码的区别
geom_text( aes( x, y + 0.1, label = tolower( greek ) ), size = 10, parse = T ) +
geom_text( aes( x, y - 0.1, label = tolower( greek ) ), size = 5 );
```
## 希腊字符, cont.
```{r echo=FALSE, message=FALSE, error=FALSE, fig.height=4, fig.width=10}
plot2;
```
## 公式示例
**注** 写公式的方式很多
\FontSmall
```{r fig.width=10, fig.height=4}
eq <- expression(paste(frac(1, sigma*sqrt(2*pi)), " ",
plain(e)^{frac(-(x-mu)^2, 2*sigma^2)}));
ggplot( data.frame(x=1:10, y=1:10), aes( x,y ) ) +
geom_point( size = 0 ) +
geom_text(data = NULL, x = 5, y = 5, size = 12,
label = as.character(eq), parse = TRUE );
```
## 公式示例2
另一种代入变量值的方法:
\FontSmall
```{r fig.width=10, fig.height=4}
library(ggplot2);
x <- 1.24;
y <- 0.6;
ex <- bquote(.(parse(text=paste( "observed (", "italic(R)^2==",
x, "^bold(", x, "), n == ", y, ")",
sep = " " ))) );
ggplot( data.frame(x=1:10, y=1:10), aes( x,y ) ) + geom_point( size = 0 ) +
geom_text(data = NULL, x = 5, y = 5, size = 8,
label = as.character(ex), parse = TRUE );
```
## 公式示例3
使用 paste 和 substitute :
\FontSmall
```{r fig.height=4, fig.width=10}
x_mean <- 1.5;
x_sd <- 1.2;
# 表达式
ex <- substitute(
paste(X[i], " ~ N(", mu, "=", m, ", ", sigma^2, "=", s2, ")"),
list(m = x_mean, s2 = x_sd^2)
);
# histogram
ggplot( data.frame( x = rnorm(100, x_mean, x_sd) ), aes( x ) ) +
geom_histogram( binwidth=0.5 ) +
ggtitle(ex); ## 为什么不需要 parse = TURE ????
```
## 下次预告
## 作业
- ```Exercises and homework``` 目录下 ```talkxx-homework.Rmd``` 文件;
- 完成时间:见钉群的要求
### important
* all codes are available at Github: https://github.com/evolgeniusteam/R-for-bioinformatics