• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ggplot2GO富集分析条形图

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

参考博客

http://blog.sciencenet.cn/blog-3406804-1166293.html

四个参数用于控制坐标轴与作图区域的位置

  • scale_x_discrete(expand = c(0, 0))
  • scale_y_discrete(expand = c(0, 0))
  • scale_x_continuous(expand = c(0, 0))
  • scale_y_continuous(expand = c(0, 0))

数据格式

自己作图代码如下

setwd("E:\\IMA\\R\\GO_draw")

library(ggplot2)

file="NJFvsLBF_up.DEG_GO_enrichment_result.xls"
outfile="NJFvsLBF_up.DEG_GO_enrichment_result.v2.pdf"

data <- read.table(file,sep="\t",header=T)

data = data[data$Over_represented_pValue <= 0.05,]
data  =  data[data$DEG_item >1,]
#head(data)

shorten_names <- function(x, n_word=4, n_char=30){
  shortname = x["Description"]
  if (length(strsplit(shortname, " ")[[1]]) > n_word || (nchar(shortname) > n_char))
  {
    if (nchar(shortname) > n_char) shortname <- substr(shortname, 1, n_char)
    y <- paste(paste(strsplit(shortname, " ")[[1]][1:min(length(strsplit(shortname," ")[[1]]), n_word)],
                     collapse=" "), "...", sep="")
    return(y)
  } 
  else
  {
    return (shortname)
  }
}

data$pretty_varname = apply(data,1,shorten_names)

draw_data = subset(data,select =c("pretty_varname","Term_type","DEG_item"))

colnames(draw_data) = c("GO_term","GO_category","Num_of_symbols_in_list_in_GO")

draw_data = draw_data[order(draw_data[,2]),]

GO_term_order=factor(draw_data$GO_term,levels=draw_data$GO_term)
COLS=c("red","blue","green")

p <- ggplot(data=draw_data, aes(x=GO_term_order,y=Num_of_symbols_in_list_in_GO, fill=GO_category)) + 
  geom_bar(stat="identity", width=0.8,position=position_dodge(1.0),colour='black',size=0.5) + scale_fill_manual(values=COLS,name="GO Terms",labels=c("BP","CC","MF")) +
  ylab("Number of Genes") + xlab("")+
  labs(title="Enriched GO Terms\n(NJFvsLBF_up)",size=6,face="plain",colour="black")+
  theme_bw()+
  theme(axis.text.x = element_text(color="black",angle=70,hjust = 1,size = 6),
        title =element_text(size=6,face="plain",colour="black"),
        axis.title = element_text(size=6,face="plain",colour="black"),
        panel.grid=element_blank(),
        panel.border = element_blank(),
        axis.line = element_line(size=0.2,colour = "black"),
        axis.text = element_text(color = "black",size = 6,face="plain"),
        plot.title = element_text(hjust = 0.5),
        legend.title = element_text(face="plain",size=6,colour = "black"),
        legend.text = element_text(face="plain",size=6,colour = "black"),
        legend.key.size = unit(0.4,"cm")
        )+scale_x_discrete(expand = c(0, 2))+
  scale_y_discrete(expand = c(0, 0),limits = c(0,5,10,15,20,25,30,35)
                     )
  #guides(fill=FALSE)

ggsave(outfile,p,width=10,height=6)


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
使用Air实现Go程序实时热重载发布时间:2022-07-10
下一篇:
Go语言从入门到放弃(四)发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap