简体   繁体   中英

Is it possible to increase the size of the bounding box in an R barplot?

Consider the following barplot code.

pdf("ThreadCreationLatency.pdf")
B <- c(52.6,26.2,0.6)
pp <- barplot(B, main="Thread Creation to First Instruction", ylab="Time (us)", 
        names.arg=c("std::thread", "Goroutines", "Arachne"),
        cex.names=1.5, cex.axis=1.5, cex.lab=1.5, cex.main=1.5, ylim=c(0,60))
text(x=pp , y=B+2, labels=as.character(B), xpd=TRUE, cex=1.5)

dev.off()

If I increase cex.lab to something like 1.6 , the label size increases, but it overflows the left bounding box of the plot and gets truncated.

Is it possible to increase the size of the bounding box on the left side so that I can have larger labels without getting truncated?

(This is the base plotting world, so do study the ?par help page.) It's helpful to remember defaults (or know how to recover them) for par('mar') :

> par('mar')
[1] 5.1 4.1 4.1 2.1

So add 1 to the left side margin which is the second of those numbers:

pdf("ThreadCreationLatency.pdf")
B <- c(52.6,26.2,0.6); par(mar=par('mar')+c(0, 1,0,0) )
pp <- barplot(B, main="Thread Creation to First Instruction", ylab="Time (us)", 
        names.arg=c("std::thread", "Goroutines", "Arachne"),
        cex.names=1.5, cex.axis=1.5, cex.lab=1.5, cex.main=1.5, ylim=c(0,60))
text(x=pp , y=B+2, labels=as.character(B), xpd=TRUE, cex=1.6)

dev.off()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM