搜索
人大经济论坛 附件下载

附件下载

所在主题:
文件名:  go_enrich_df.txt
资料下载链接地址: https://bbs.pinggu.org/a-3494478.html
附件大小:
请教各位朋友,我在绘制分面图时遇到问题:1.每个子图有10个分类项目,为何Y轴有40项(4大类/子图项目的总和),如何使每个子图的Y轴只显示对应的10个项目?
2.每个数据的Y轴标签,前面已经截短了,如何显示?多谢朋友们!
  1. go_enrich_df <- read.table('go_enrich_df.txt', sep ='\t', header=T)

  2. ## numbers as data on x axis
  3. go_enrich_df$number <- factor(rev(1:nrow(go_enrich_df)))

  4. ## shorten the names of GO terms
  5. shorten_names <- function(x, n_word=4, n_char=40){
  6. if (length(strsplit(x, " ")[[1]]) > n_word || (nchar(x) > 40))
  7. {
  8. if (nchar(x) > 40) x <- substr(x, 1, 40)
  9. x <- paste(paste(strsplit(x, " ")[[1]][1:min(length(strsplit(x," ")[[1]]), n_word)], collapse=" "), "...", sep="")
  10. return(x)
  11. }
  12. else
  13. {
  14. return(x)
  15. }
  16. }

  17. labels <- (sapply(
  18. levels(factor(go_enrich_df$Term))[as.numeric(go_enrich_df$number)],
  19. shorten_names))
  20. names(labels) <- rev(1:nrow(go_enrich_df))

  21. library(ggplot2)
  22. p <- ggplot(data=go_enrich_df, aes(x=FoldEnrichment, y=Term, fill=PValue, size = GeneNumber)) +
  23. geom_point(shape=21, colour="black", alpha=0.95) +
  24. # facet_wrap(type ~ ) +
  25. facet_grid(type ~ .) +
  26. # scale_fill_gradient2(low="blue",high = "red") +
  27. # scale_fill_manual(values = CPCOLS) +
  28. theme_bw() +
  29. scale_y_discrete(labels=labels) +
  30. theme(axis.text=element_text(face = "bold", color="gray50")) +
  31. labs(y = "GO term /KEGG Pathway", title = "Enriched GO Terms /KEGG Pathway") # color = PValue, size = GeneNumber,

  32. p
复制代码



    熟悉论坛请点击新手指南
下载说明
1、论坛支持迅雷和网际快车等p2p多线程软件下载,请在上面选择下载通道单击右健下载即可。
2、论坛会定期自动批量更新下载地址,所以请不要浪费时间盗链论坛资源,盗链地址会很快失效。
3、本站为非盈利性质的学术交流网站,鼓励和保护原创作品,拒绝未经版权人许可的上传行为。本站如接到版权人发出的合格侵权通知,将积极的采取必要措施;同时,本站也将在技术手段和能力范围内,履行版权保护的注意义务。
(如有侵权,欢迎举报)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

GMT+8, 2026-1-29 20:21