• 主页
  • 课程

    关于课程

    • 课程归档
    • 成为一名讲师
    • 讲师信息
    同等学历教学

    同等学历教学

    免费
    阅读更多
  • 特色
    • 展示
    • 关于我们
    • 问答
  • 事件
  • 个性化
  • 博客
  • 联系
  • 站点资源
    有任何问题吗?
    (00) 123 456 789
    weinfoadmin@weinformatics.cn
    注册登录
    恒诺新知
    • 主页
    • 课程

      关于课程

      • 课程归档
      • 成为一名讲师
      • 讲师信息
      同等学历教学

      同等学历教学

      免费
      阅读更多
    • 特色
      • 展示
      • 关于我们
      • 问答
    • 事件
    • 个性化
    • 博客
    • 联系
    • 站点资源

      未分类

      • 首页
      • 博客
      • 未分类
      • Plot.ly Volcano Plot Example

      Plot.ly Volcano Plot Example

      • 发布者 weinfoeditor
      • 分类 未分类
      • 日期 2021年7月20日
      • 评论 0评论

      https://stevekm.github.io/2016/09/24/Plot.ly-Volcano-Plot.html

      Stephen Kelly

      9/24/2016

      In this example, I will demonstrate how to use gene differential binding data to create a volcano plot using R and Plot.ly. This dataset was generated by DiffBind during the analysis of a ChIP-Seq experiment. Each entry represents a bound peak that was differentially expressed between groups of samples.

      First, install any libraries you might not have, load the Plot.ly library, and load the file containing your differential binding data.Hide

      # dependencies:
      # install.packages("ggplot2")
      # install.packages("gridExtra")
      # install.packages("plotly")
      suppressPackageStartupMessages(library("plotly"))
      
      # path to the DiffBind table with genes
      input_file <- "../sample_data/diff_bind.Treatment4-ChIPSeq-vs-Control-ChIPSeq.p100.csv"
      
      # read the file into a dataframe
      diff_df <- read.delim(file = input_file,header = TRUE,sep = ',')
      
      # check some attributes of the data
      colnames(diff_df)
      ##  [1] "seqnames"                   "start"                     
      ##  [3] "end"                        "width"                     
      ##  [5] "strand"                     "Conc"                      
      ##  [7] "Conc_Treatment4.ChIPSeq"    "Conc_Control.ChIPSeq"      
      ##  [9] "Fold"                       "p.value"                   
      ## [11] "FDR"                        "Sample1.Treatment4.ChIPSeq"
      ## [13] "Sample2.Treatment4.ChIPSeq" "Sample3.Treatment4.ChIPSeq"
      ## [15] "Sample7.Control.ChIPSeq"    "Sample8.Control.ChIPSeq"   
      ## [17] "Sample9.Control.ChIPSeq"    "feature"                   
      ## [19] "external_gene_name"         "gene_biotype"              
      ## [21] "start_position"             "end_position"              
      ## [23] "insideFeature"              "distancetoFeature"         
      ## [25] "shortestDistance"           "fromOverlappingOrNearest"

      Hide

      dim(diff_df)
      ## [1] 3192   26

      This table has a lot of information, but for this plot we only need the following:

      • Gene names
      • Fold change value
      • Statistical significance (e.g. p value, adjusted p value, etc.)

      In this case we are using the False Discovery Rate as our signficance value.Hide

      # keep only the fields needed for the plot
      # FDR = false discovery rate = adjusted p value = significance 
      diff_df <- diff_df[c("external_gene_name", "Fold", "FDR")]
      
      # preview the dataset; data required for the plot
      head(diff_df)
      ##   external_gene_name  Fold      FDR
      ## 1      RP11-431K24.1 -4.13 1.04e-05
      ## 2              UBE4B  2.42 8.71e-06
      ## 3             UBIAD1  4.27 5.50e-06
      ## 4             UBIAD1  1.89 2.16e-04
      ## 5             UBIAD1  2.74 8.59e-05
      ## 6             UBIAD1  3.42 1.39e-08

      In order to color the points on the plot easier, we will add an extra column to the data to mark whether each entry passes our cutoffs for Fold change and Significance. Our criteria for this experiment were:

      • Fold change > 1.5x change
      • FDR < 0.05 (similar to a p value of <0.05)

      Hide

      # add a grouping column; default value is "not significant"
      diff_df["group"] <- "NotSignificant"
      
      # for our plot, we want to highlight 
      # FDR < 0.05 (significance level)
      # Fold Change > 1.5
      
      # change the grouping for the entries with significance but not a large enough Fold change
      diff_df[which(diff_df['FDR'] < 0.05 & abs(diff_df['Fold']) < 1.5 ),"group"] <- "Significant"
      
      # change the grouping for the entries a large enough Fold change but not a low enough p value
      diff_df[which(diff_df['FDR'] > 0.05 & abs(diff_df['Fold']) > 1.5 ),"group"] <- "FoldChange"
      
      # change the grouping for the entries with both significance and large enough fold change
      diff_df[which(diff_df['FDR'] < 0.05 & abs(diff_df['Fold']) > 1.5 ),"group"] <- "Significant&FoldChange"

      We would also like to label the top 10 genes; the ones with the highest positive or negative fold changes and FDR values.Hide

      # Find and label the top peaks..
      top_peaks <- diff_df[with(diff_df, order(Fold, FDR)),][1:5,]
      top_peaks <- rbind(top_peaks, diff_df[with(diff_df, order(-Fold, FDR)),][1:5,])
      
      
      # Add gene labels to the plot
      # Single Gene Annotation example
      # m <- diff_df[with(diff_df, order(Fold, FDR)),][1,]
      # a <- list(
      #   x = m[["Fold"]],
      #   y = -log10(m[["FDR"]]),
      #   text = m[["external_gene_name"]],
      #   xref = "x",
      #   yref = "y",
      #   showarrow = TRUE,
      #   arrowhead = 7,
      #   ax = 20,
      #   ay = -40
      # )
      
      # Add gene labels for all of the top genes we found
      # here we are creating an empty list, and filling it with entries for each row in the dataframe
      # each list entry is another list with named items that will be used by Plot.ly
      a <- list()
      for (i in seq_len(nrow(top_peaks))) {
        m <- top_peaks[i, ]
        a[[i]] <- list(
          x = m[["Fold"]],
          y = -log10(m[["FDR"]]),
          text = m[["external_gene_name"]],
          xref = "x",
          yref = "y",
          showarrow = TRUE,
          arrowhead = 0.5,
          ax = 20,
          ay = -40
        )
      }

      Now we can make the plotHide

      # make the Plot.ly plot
      p <- plot_ly(data = diff_df, x = Fold, y = -log10(FDR), text = external_gene_name, mode = "markers", color = group) %>% 
        layout(title ="Volcano Plot") %>%
        layout(annotations = a)
      p

      −50505101520Volcano PlotFold-log10(FDR)Significant&FoldChangeSignificantNotSignificantFoldChangeRP11-770E5.1MIR1208UQCC1PMEPA1CHD1LSORL1CTBP2P1ACSS1CTBP2P1SORL1Hide

      # to save plot to a HTML file:
      # htmlwidgets::saveWidget(as.widget(p), "graph.html")
      
      # System Information
      sessionInfo()
      ## R version 3.3.1 (2016-06-21)
      ## Platform: x86_64-redhat-linux-gnu (64-bit)
      ## Running under: CentOS release 6.8 (Final)
      ## 
      ## locale:
      ##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
      ##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
      ##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
      ##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
      ##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
      ## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
      ## 
      ## attached base packages:
      ## [1] stats     graphics  grDevices utils     datasets  methods   base     
      ## 
      ## other attached packages:
      ## [1] plotly_3.6.0  ggplot2_2.1.0
      ## 
      ## loaded via a namespace (and not attached):
      ##  [1] Rcpp_0.12.6        knitr_1.13         magrittr_1.5      
      ##  [4] munsell_0.4.3      colorspace_1.2-6   R6_2.1.2          
      ##  [7] stringr_1.0.0      httr_1.2.1         plyr_1.8.4        
      ## [10] tools_3.3.1        grid_3.3.1         gtable_0.2.0      
      ## [13] htmltools_0.3.5    yaml_2.1.13        digest_0.6.10     
      ## [16] assertthat_0.1     tibble_1.1         gridExtra_2.2.1   
      ## [19] RColorBrewer_1.1-2 tidyr_0.6.0        viridis_0.3.4     
      ## [22] base64enc_0.1-3    htmlwidgets_0.7    evaluate_0.9      
      ## [25] rmarkdown_1.0      stringi_1.1.1      scales_0.4.0      
      ## [28] jsonlite_1.0

      1 References

      https://plot.ly/r/offline/https://plot.ly/r/https://plot.ly/r/text-and-annotations/https://plot.ly/r/reference/#Layout_and_layout_style_objectshttp://www.gettinggeneticsdone.com/2014/05/r-volcano-plots-to-visualize-rnaseq-microarray.html

      请关注“恒诺新知”微信公众号,感谢“R语言“,”数据那些事儿“,”老俊俊的生信笔记“,”冷🈚️思“,“珞珈R”,“生信星球”的支持!

      • 分享:
      作者头像
      weinfoeditor

      上一篇文章

      教程:Gene Set Enrichment Analysis
      2021年7月20日

      下一篇文章

      Tutorial:Enrichment Analysis, Clustering and Scoring with pathfindR
      2021年7月20日

      你可能也喜欢

      2-1675088548
      lncRNA和miRNA生信分析系列讲座免费视频课和课件资源包,干货满满
      30 1月, 2023
      9-1675131201
      如何快速批量修改 Git 提交记录中的用户信息
      26 1月, 2023
      8-1678501786
      肿瘤细胞通过改变CD8+ T细胞中的丙酮酸利用和琥珀酸信号来调控抗肿瘤免疫应答。
      7 12月, 2022

      留言 取消回复

      要发表评论,您必须先登录。

      搜索

      分类

      • R语言
      • TCGA数据挖掘
      • 单细胞RNA-seq测序
      • 在线会议直播预告与回放
      • 数据分析那些事儿分类
      • 未分类
      • 生信星球
      • 老俊俊的生信笔记

      投稿培训

      免费

      alphafold2培训

      免费

      群晖配置培训

      免费

      最新博文

      Nature | 单细胞技术揭示衰老细胞与肌肉再生
      301月2023
      lncRNA和miRNA生信分析系列讲座免费视频课和课件资源包,干货满满
      301月2023
      如何快速批量修改 Git 提交记录中的用户信息
      261月2023
      logo-eduma-the-best-lms-wordpress-theme

      (00) 123 456 789

      weinfoadmin@weinformatics.cn

      恒诺新知

      • 关于我们
      • 博客
      • 联系
      • 成为一名讲师

      链接

      • 课程
      • 事件
      • 展示
      • 问答

      支持

      • 文档
      • 论坛
      • 语言包
      • 发行状态

      推荐

      • iHub汉语代码托管
      • iLAB耗材管理
      • WooCommerce
      • 丁香园论坛

      weinformatics 即 恒诺新知。ICP备案号:粤ICP备19129767号

      • 关于我们
      • 博客
      • 联系
      • 成为一名讲师

      要成为一名讲师吗?

      加入数以千计的演讲者获得100%课时费!

      现在开始

      用你的站点账户登录

      忘记密码?

      还不是会员? 现在注册

      注册新帐户

      已经拥有注册账户? 现在登录

      close
      会员购买 你还没有登录,请先登录
      • ¥99 VIP-1个月
      • ¥199 VIP-半年
      • ¥299 VIP-1年
      在线支付 激活码

      立即支付
      支付宝
      微信支付
      请使用 支付宝 或 微信 扫码支付
      登录
      注册|忘记密码?