文本太长怎样处理?

2019-08-09  本文已影响0人  一路向前_莫问前程_前程似锦
转自Y叔叔

这个问题其实很简单,用stringr包的str_wrap来完成文本自动换行就行了。这里使用clusterProfilerbarplot来演示一下:

library(stringr)
library(ggplot2)
library(clusterProfiler)
data(geneList)de <- names(geneList)[1:100]
x <- enrichKEGG(de)
p <- barplot(x) 
p + scale_x_discrete(labels=function(x) str_wrap(x, width=10))

doyplot

library(stringr)
library(ggplot2)
p1 <- dotplot(ego2, showCategory=20) + ggtitle("dotplot for GO")+scale_y_discrete(labels=function(y) str_wrap(y, width=40))
p2 <- dotplot(kegg, showCategory=20) + ggtitle("dotplot for KEGG")+scale_y_discrete(labels=function(x) str_wrap(x, width=40))
pdf("combinde.pdf",width = 15,height = 9)
plot_grid(p2, p1, ncol=2)
dev.off()

上一篇 下一篇

猜你喜欢

热点阅读