条形图标签太长,是否可以设置“标签宽度”

时间:2018-11-21 20:00:45

标签: r plot graph bar-chart

我正在尝试在beside = TRUE的位置创建一个堆积的条形图。这是用于生成该图的数据;

significant <- c(27, 44, 25, 54, 40, 31, 25,  9, 57, 59)
annotated <- c(119, 267, 109, 373, 250, 173, 124,  20, 452, 478)
names <- c("mitochondrial gene expression","ncRNA metabolic process", 
           "mitochondrial translation", "translation", 
           "ribonucleoprotein complex biogenesis", "ribosome biogenesis", 
           "rRNA metabolic process", "transcription preinitiation complex asse...", 
           "peptide biosynthetic process", "amide biosynthetic process")
data = rbind(significant, annotated)
colnames(data) <- names
rownames(data) <- c("significant", "annotated")

我的绘图代码是;

printBarPlots <- function(input, main){
  data = rbind(input[,4], input[,3])

  colnames(data)= input[,2]
  rownames(data)=c("Significant", "Annotated")
  par(mar=c(5,9,4,2))
  mybar = barplot(data, width = 3, xlab = "Number of genes", main = main, 
                  horiz = T, cex.axis = 0.8, beside = TRUE, las = 1, 
                  cex.names = 0.8, legend = T, args.legend = list(x="right"))
}

barplot showing long margins on the left handside

使用此代码,条形标签延伸到绘图的左侧。我的问题与this question不同,因为在每个空格处分割条形码名称仍然需要有一个小的cex.names。是否可以指定不是将诸如“转录预初始化复杂资产...”这样的内容写在一行上,而是可以将其分布在两行上(例如下面),以便更好地利用空间?或者,也许是某种代码,可以将一定数量的字母后面的名称拆分为不同的行(例如,在13个字符后开始新行)。

“转录预初始化

复杂的资产...”

0 个答案:

没有答案