I am trying to create a stacked barplot where beside = TRUE
. Here is the data used to generate this figure;
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")
My plotting code is;
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"))
}
Using this code, the bar labels extend far to the left of my plot. My question is unlike this questionbecause splitting the bar names at each space would still require having to have a small cex.names
. Is it possible to specify that rather than having something like "transcription preinitiation complex asse..." written on one line, it can be spread out over two lines, such as below, to make better use of space? Or perhaps, some sort of code to split names onto different lines following a certain amount of letters (e.g. start new line after 13 characters).
"transcription preinitiation
complex asse..."