富集分析图左侧名称拥挤解决办法
2021-07-16 本文已影响0人
医只蜗牛
富集分析图左侧名称拥挤解决办法
-主要修改地方【对比旧代码】
1.theme_bw(base_size = 7)
2.axis.text.y = element_text(size = 7))
library( "ggplot2" )
{
kegg_down_dt <- as.data.frame( kk.down )
kegg_up_dt <- as.data.frame( kk.up )
down_kegg <- kegg_down_dt[ kegg_down_dt$pvalue < 0.05, ]
down_kegg$group = -1
up_kegg <- kegg_up_dt[ kegg_up_dt$pvalue < 0.05, ]
up_kegg$group = 1
dat = rbind( up_kegg, down_kegg )
dat$pvalue = -log10( dat$pvalue )
dat$pvalue = dat$pvalue * dat$group
dat = dat[ order( dat$pvalue, decreasing = F ), ]
g_kegg<- ggplot(dat, aes(x=reorder(Description,order(pvalue, decreasing = F)), y=pvalue, fill=group)) +
geom_bar(stat="identity") +
scale_fill_gradient(low="blue",high="red",guide = FALSE) +
scale_x_discrete(name ="Pathway names") +
scale_y_continuous(name ="log10P-value") +
coord_flip() + theme_bw(base_size = 7)+
theme(plot.title = element_text(hjust = 0.5), axis.text.y = element_text(size = 7))+
ggtitle("Pathway Enrichment")
###修改了数值,【7,可修改】,下面为旧代码。
# g_kegg <- ggplot( dat,
# aes(x = reorder( Description, order( pvalue, decreasing=F ) ), y = pvalue, fill = group)) +
# geom_bar( stat = "identity" ) +
# scale_fill_gradient( low = "blue", high = "red", guide = F ) +
# scale_x_discrete( name = "Pathway names" ) +
# scale_y_continuous( name = "log10P-value" ) +
# coord_flip() + theme_bw() + theme( plot.title = element_text( hjust = 0.5 ) ) +
# ggtitle( "Pathway Enrichment" )
print( g_kegg )
ggsave( g_kegg, filename = 'kegg_up_down.png' )
}