R语言做生信Cook R数据-R语言-图表-决策-Linux-Python

《Modern Statistics for Modern Bi

2019-03-09  本文已影响11人  热衷组培的二货潜

《Modern Statistics for Modern Biology》Chapter 一: 离散数据模型的预测(1.1 - 1.3)

《Modern Statistics for Modern Biology》Chapter 一: 离散数据模型的预测(1.4 - 1.5)

《Modern Statistics for Modern Biology》Chapter 二: 统计建模(2.1-2.3)

《Modern Statistics for Modern Biology》Chapter 二: 统计建模(2.4-2.5)

《Modern Statistics for Modern Biology》Chapter 二 统计建模(2.6 - 2.7)

《Modern Statistics for Modern Biology》Chapter 二 统计建模(2.8 - 2.9)

《Modern Statistics for Modern Biology》Chapter 二 统计建模(2.10 完结)

从这章开始最开始记录一些markdown等小知识
$\hat{p}=\frac{1}{12}$\hat{p}=\frac{1}{12}
掌握R语言中的apply函数族
卡方检验
Hardy-Weinberg equilibrium( 哈迪-温伯格平衡 )
带你理解beta分布
简单介绍一下R中的几种统计分布及常用模型

  • 统计分布每一种分布有四个函数:d――density(密度函数),p――分布函数,q――分位数函数,r――随机数函数。比如,正态分布的这四个函数为dnorm,pnorm,qnorm,rnorm。下面我们列出各分布后缀,前面加前缀d、p、q或r就构成函数名:norm:正态t:t分布f:F分布chisq:卡方(包括非中心) unif:均匀exp:指数,weibull:威布尔,gamma:伽玛beta:贝塔 lnorm:对数正态,logis:逻辑分布,cauchy:柯西binom:二项分布geom:几何分布hyper:超几何nbinom:负二项pois:泊松 signrank:符号秩,wilcox:秩和tukey:学生化极差
    如何预测一条序列是否含有CpG岛
    图片输出尽量保存为矢量图

3、R语言中的高质量图形

3.1 这一章的目标

3.2 基础R绘图

> head(DNase)
  Run       conc density
1   1 0.04882812   0.017
2   1 0.04882812   0.018
3   1 0.19531250   0.121
4   1 0.19531250   0.124
5   1 0.39062500   0.206
6   1 0.39062500   0.215
> plot(DNase$conc, DNase$density)
图 3.2
> plot( DNase$conc, DNase$density, 
+ ylab = attr(DNase, "labels")$y,
+ xlab = paste(attr(DNase, "labels")$x, attr(DNase, "units")$x),
+ pch = 3,
+ col = "blue")
> attr(DNase, "labels")
$`x`
[1] "DNase concentration"

$y
[1] "Optical density"
> attr(DNase, "units")
$`x`
[1] "(ng/ml)"
图 3.3 这里严重没搞懂,明明横坐标12.5的位置就对应两个值,这里怎么会有这么多值
横坐标12.5

问题

> hist(DNase$density, breaks=25, main = "")
> boxplot(density~Run, data = DNase)
图 3.4

3.3 示例数据集

> BiocManager::install("Hiiragi2013", version = "3.8")
> library("Hiiragi2013")  ## 数据比较大,如果安装失败,重复运行上面代码几次就好
> data("x")
> dim(Biobase::exprs(x))
[1] 45101   101
> head(pData(x), n = 2)
        File.name Embryonic.day Total.number.of.cells lineage genotype   ScanDate sampleGroup sampleColour
1 E3.25  1_C32_IN         E3.25                    32               WT 2011-03-16       E3.25      #CAB2D6
2 E3.25  2_C32_IN         E3.25                    32               WT 2011-03-16       E3.25      #CAB2D6
> library("dplyr")
> groups = group_by(pData(x), sampleGroup) %>%
+   summarise(n = n(), color = unique(sampleColour))
> groups
# A tibble: 8 x 3
  sampleGroup         n color  
  <chr>           <int> <chr>  
1 E3.25              36 #CAB2D6
2 E3.25 (FGF4-KO)    17 #FDBF6F
3 E3.5 (EPI)         11 #A6CEE3
4 E3.5 (FGF4-KO)      8 #FF7F00
5 E3.5 (PE)          11 #B2DF8A
6 E4.5 (EPI)          4 #1F78B4
7 E4.5 (FGF4-KO)     10 #E31A1C
8 E4.5 (PE)           4 #33A02C
f(x) %>% g(y) %>% h
h(g(f(x), y))

3.4 ggplot2

> library(ggplot2)
> ggplot(DNase, aes(x = conc, y = density)) + geom_point()
图 3.6
> ggplot(groups, aes(sampleGroup, n)) + geom_bar(stat = "identity")

图 3.7

接下来省略中间话语,主要注重于代码的学习

> groupColor = setNames(groups$color, groups$sampleGroup)
>  groupColor 
          E3.25 E3.25 (FGF4-KO)      E3.5 (EPI)  E3.5 (FGF4-KO)       E3.5 (PE)      E4.5 (EPI)  E4.5 (FGF4-KO) 
      "#CAB2D6"       "#FDBF6F"       "#A6CEE3"       "#FF7F00"       "#B2DF8A"       "#1F78B4"       "#E31A1C" 
      E4.5 (PE) 
      "#33A02C" 
> ggplot(groups, aes(x = sampleGroup, y = n, fill = sampleGroup)) +
+   geom_bar(stat = "identity") +
+   scale_fill_manual(values = groupColor, name = "Groups") +
+   theme(axis.text.x = element_text(angle = 90, hjust = 1))
图 3.8

3.4.1 Data flow

> gg = ggplot(DNase, aes(x = conc, y = density)) + geom_point()
> gg
> print(gg)

3.4.2 保存图片
> ggsave("DNAse-histogram-demo.pdf", plot = gg)
上一篇 下一篇

猜你喜欢

热点阅读