文本太长怎样处理?

转自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()

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容