r语言学习ggplot2绘图R语言可视化

ggpubr包系列学习教程(七 )

2018-09-09  本文已影响18人  Davey1220

使用ggmaplot函数绘制MA图


加载所需R包

library(ggpubr)

基本用法:

Usage

ggmaplot(data, fdr = 0.05, fc = 1.5, genenames = NULL,
         detection_call = NULL, size = NULL, font.label = c(12, "plain", "black"), 
         label.rectangle = FALSE, palette = c("#B31B21", "#1465AC", "darkgray"), 
         top = 15, select.top.method = c("padj", "fc"), main = NULL,
         xlab = "Log2 mean expression", ylab = "Log2 fold change",
         ggtheme = theme_classic(), ...)

常用参数:

Arguments

data    #差异基因分析结果 an object of class DESeqResults, get_diff, DE_Results, matrix or data frame containing the columns baseMean, log2FoldChange, and padj. Rows are genes.
        #baseMean: the mean expression of genes in the two groups.
        #log2FoldChange: the log2 fold changes of group 2 compared to group 1
        #padj: the adjusted p-value of the used statiscal test.
fdr    #设定fdr阈值 Accepted false discovery rate for considering genes as differentially expressed.
fc    #设定fc阈值 the fold change threshold. Only genes with a fold change >= fc and padj <= fdr are considered as significantly differentially expressed.
genenames    #基因名 a character vector of length nrow(data) specifying gene names corresponding to each row. Used for point labels.
detection_call    #选出特定表达模式的基因进行展示 a numeric vector with length = nrow(data), specifying if the genes is expressed (value = 1) or not (value = 0). For example detection_call = c(1, 1, 0, 1, 0, 1). Default is NULL. If detection_call column is available in data, it will be used.
size    #points size.
font.label    #a vector of length 3 indicating respectively the size (e.g.: 14), the style (e.g.: "plain", "bold", "italic", "bold.italic") and the color (e.g.: "red") of point labels. For example font.label = c(14, "bold", "red").
label.rectangle    #logical value. If TRUE, add rectangle underneath the text, making it easier to read.
palette    #the color palette to be used for coloring or filling by groups. Allowed values include "grey" for grey color palettes; brewer palettes e.g. "RdBu", "Blues", ...; or custom color palette e.g. c("blue", "red"); and scientific journal palettes from ggsci R package, e.g.: "npg", "aaas", "lancet", "jco", "ucscgb", "uchicago", "simpsons" and "rickandmorty".
top    #选定top基因进行展示 the number of top genes to be shown on the plot. Use top = 0 to hide to gene labels.
select.top.method    #methods to be used for selecting top genes. Allowed values include "padj" and "fc" for selecting by adjusted p values or fold changes, respectively.
main    #plot main title.
xlab    #character vector specifying x axis labels. Use xlab = FALSE to hide xlab.
ylab    #character vector specifying y axis labels. Use ylab = FALSE to hide ylab.
ggtheme    #function, ggplot2 theme name. Default value is theme_pubr(). Allowed values include ggplot2 official themes: theme_gray(), theme_bw(), theme_minimal(), theme_classic(), theme_void()
...    #other arguments to be passed to ggpar.

使用示例

Examples

# 加载数据集
data(diff_express)
head(diff_express)
##                     name     baseMean log2FoldChange         padj
## ENSG00000000003   TSPAN6    0.1184475      0.0000000           NA
## ENSG00000000419     DPM1 1654.4618144      0.6789538 5.280802e-02
## ENSG00000000457    SCYL3  681.0463277      1.5263838 3.915112e-07
## ENSG00000000460 C1orf112  389.7226640      3.8933573 1.180333e-14
## ENSG00000000938      FGR  364.7810090     -2.3554014 1.559228e-04
## ENSG00000000971      CFH    1.1346239      1.2932740 4.491812e-01
##                 detection_call
## ENSG00000000003              0
## ENSG00000000419              1
## ENSG00000000457              1
## ENSG00000000460              1
## ENSG00000000938              1
## ENSG00000000971              0
# Default plot
p1 <- ggmaplot(diff_express, fdr = 0.05, fc = 2, size = 0.4,
               palette = c("red","green","gray"))
p1
p1
p2 <- ggmaplot(diff_express, main = expression("Group 1" %->% "Group 2"),
         fdr = 0.05, fc = 2, size = 0.4,
         palette = c("#B31B21", "#1465AC", "darkgray"),
         genenames = as.vector(diff_express$name),
         xlab = "M",ylab = "A",
         legend = "top", top = 20,
         font.label = c("bold", 11),
         font.legend = "bold",
         font.main = "bold",
         ggtheme = ggplot2::theme_minimal())
p2
p2
# Add rectangle around labels
p3 <- ggmaplot(diff_express, main = expression("Group 1" %->% "Group 2"),
         fdr = 0.05, fc = 2, size = 0.4,
         palette = c("#B31B21", "#1465AC", "darkgray"),
         genenames = as.vector(diff_express$name),
         legend = "top", top = 20,
         font.label = c("bold", 11), label.rectangle = TRUE,
         font.legend = "bold", select.top.method = "padj",
         font.main = "bold",
         ggtheme = ggplot2::theme_minimal())
p3
p3
p4 <- ggmaplot(diff_express, main = expression("Group 1" %->% "Group 2"),
               fdr = 0.05, fc = 2, size = 0.5,
               palette = c("#B31B21", "#1465AC", "darkgray"),
               genenames = as.vector(diff_express$name),
               legend = "top", top = 20, select.top.method = "fc",
               font.label = c("bold", 11), label.rectangle = TRUE,
               font.legend = "bold",
               font.main = "bold",
               ggtheme = ggplot2::theme_minimal())
p4
p4

参考来源:

https://www.rdocumentation.org/packages/ggpubr/versions/0.1.4/topics/ggmaplot

sessionInfo()
## R version 3.5.1 (2018-07-02)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: OS X El Capitan 10.11.3
## 
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] zh_CN.UTF-8/zh_CN.UTF-8/zh_CN.UTF-8/C/zh_CN.UTF-8/zh_CN.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] ggpubr_0.1.7.999 magrittr_1.5     ggplot2_3.0.0   
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.18     rstudioapi_0.7   bindr_0.1.1      knitr_1.20      
##  [5] tidyselect_0.2.4 munsell_0.5.0    colorspace_1.3-2 R6_2.2.2        
##  [9] rlang_0.2.2      stringr_1.3.1    plyr_1.8.4       dplyr_0.7.6     
## [13] tools_3.5.1      grid_3.5.1       gtable_0.2.0     withr_2.1.2     
## [17] htmltools_0.3.6  assertthat_0.2.0 yaml_2.2.0       lazyeval_0.2.1  
## [21] rprojroot_1.3-2  digest_0.6.16    tibble_1.4.2     crayon_1.3.4    
## [25] bindrcpp_0.2.2   purrr_0.2.5      ggrepel_0.8.0    glue_1.3.0      
## [29] evaluate_0.11    rmarkdown_1.10   labeling_0.3     stringi_1.2.4   
## [33] compiler_3.5.1   pillar_1.3.0     scales_1.0.0     backports_1.1.2 
## [37] pkgconfig_2.0.2
上一篇 下一篇

猜你喜欢

热点阅读