Lesson 01 for Plotting in R for Biologists

mark

简介

老早之前就知道了这门课 Plotting in R for Biologists,一直没有去学习一下,最近花时间看了一遍videos,发现讲的很不错,虽然有一节有一知识点讲的不是很清楚。学了一遍之后记点笔记,这是lesson1的学习笔记。这一节主要讲了数据读取、快速绘图以及图形保存。

数据

library(ggplot2)
filename <- "/home/taoyan/Plotting in R for Biologists/Lesson-01/Encode_HMM_data.txt"
my_data <- read.csv(filename, sep="\t", header=FALSE)
# 查看一下数据
head(my_data)
##     V1    V2    V3                V4 V5 V6    V7    V8          V9
## 1 chr1 10000 10600 15_Repetitive/CNV  0  . 10000 10600 245,245,245
## 2 chr1 10600 11137 13_Heterochrom/lo  0  . 10600 11137 245,245,245
## 3 chr1 11137 11737       8_Insulator  0  . 11137 11737  10,190,254
## 4 chr1 11737 11937       11_Weak_Txn  0  . 11737 11937 153,255,102
## 5 chr1 11937 12137   7_Weak_Enhancer  0  . 11937 12137   255,252,4
## 6 chr1 12137 14537       11_Weak_Txn  0  . 12137 14537 153,255,102

对数据列名重命名

names(my_data)[1:4] <- c("chrom","start","end","type")
head(my_data)
##   chrom start   end              type V5 V6    V7    V8          V9
## 1  chr1 10000 10600 15_Repetitive/CNV  0  . 10000 10600 245,245,245
## 2  chr1 10600 11137 13_Heterochrom/lo  0  . 10600 11137 245,245,245
## 3  chr1 11137 11737       8_Insulator  0  . 11137 11737  10,190,254
## 4  chr1 11737 11937       11_Weak_Txn  0  . 11737 11937 153,255,102
## 5  chr1 11937 12137   7_Weak_Enhancer  0  . 11937 12137   255,252,4
## 6  chr1 12137 14537       11_Weak_Txn  0  . 12137 14537 153,255,102

绘图

对不同染色体上的不同type绘制柱形图

ggplot(data = my_data, aes(x= chrom, fill= type))+geom_bar()

mark

保存

如果想直接保存图片到文件中,可以用dev.off,R语言支持多种图形类型

png("Lesson-01/plot.png")
ggplot(my_data,aes(x=chrom,fill=type)) + geom_bar()
dev.off()

tiff("Lesson-01/plot.tiff")
ggplot(my_data,aes(x=chrom,fill=type)) + geom_bar()
dev.off()

jpeg("Lesson-01/plot.jpg")
ggplot(my_data,aes(x=chrom,fill=type)) + geom_bar()
dev.off()

pdf("Lesson-01/plot.pdf")
ggplot(my_data,aes(x=chrom,fill=type)) + geom_bar()
dev.off()

# 设置清晰度
png("Lesson-01/plot_hi_res.png",1000,1000)
ggplot(my_data,aes(x=chrom,fill=type)) + geom_bar()
dev.off()

这节课比较简单,没什么知识点,当然如果R语言没入门的话读个数据都困难重重,所以如果基础不太好的可以直接去youtube看视频,讲的很详细。

##SessionInfo

sessionInfo()
## R version 3.4.3 (2017-11-30)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 17.10
## 
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
## LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3
## 
## locale:
##  [1] LC_CTYPE=zh_CN.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=zh_CN.UTF-8        LC_COLLATE=zh_CN.UTF-8    
##  [5] LC_MONETARY=zh_CN.UTF-8    LC_MESSAGES=zh_CN.UTF-8   
##  [7] LC_PAPER=zh_CN.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=zh_CN.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] ggplot2_2.2.1
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.14     digest_0.6.14    rprojroot_1.3-2  plyr_1.8.4      
##  [5] grid_3.4.3       gtable_0.2.0     backports_1.1.2  magrittr_1.5    
##  [9] evaluate_0.10.1  scales_0.5.0     pillar_1.1.0     rlang_0.1.6     
## [13] stringi_1.1.6    lazyeval_0.2.1   rmarkdown_1.8    labeling_0.3    
## [17] tools_3.4.3      stringr_1.2.0    munsell_0.4.3    yaml_2.1.16     
## [21] compiler_3.4.3   colorspace_1.3-2 htmltools_0.3.6  knitr_1.18      
## [25] tibble_1.4.1
Researcher

I am a PhD student of Crop Genetics and Breeding at the Zhejiang University Crop Science Lab. My research interests covers a range of issues:Population Genetics Evolution and Ecotype Divergence Analysis of Oilseed Rape, Genome-wide Association Study (GWAS) of Agronomic Traits.

comments powered by Disqus