简体   繁体   中英

R is plotting labels off the page

i'm running the following:

png(filename="figure.png", width=900, bg="white")
barplot(c(1.1, 0.8, 0.7), horiz=TRUE, border="blue", axes=FALSE, col="darkblue")
axis(2, at=1:3, lab=c("elephant", "hippo", "snorkel"), las=1, cex.axis=1.3)
dev.off()

and the labels on the left are appearing off the page. I can't seem to figure out how to fix it. Any ideas?

Thanks.

You haven't left enough space in the left margin for labels that long. Try:

png(filename="figure.png", width=900, bg="white")
par(mar=c(5,6,4,1)+.1)
barplot(c(1.1, 0.8, 0.7), horiz=TRUE, border="blue", axes=FALSE, col="darkblue")
axis(2, at=1:3, lab=c("elephant", "hippo", "snorkel"), las=1, cex.axis=1.3)
dev.off()

The 'mar' argument of 'par' sets the width of the margins in the order: 'bottom', 'left', 'top', 'right'. The default is to set 'left' to 4, here I have changed it to 6.

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