Wednesday, November 16, 2011

Adjust par margins par('mar') to that axis labels fit inside the window

Adjust par margins to that axis labels fit inside the window

http://ww2.coastal.edu/kingw/statistics/R-tutorials/graphs.html

We could make the font smaller, but I'm stubborn. I don't wanna! The data labels are printed in the margins of the plotting area, and we can see what those are by querying the "mar" settings...

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

I don't know the units (and the help page does not give up this info--apparently, it is top secret), but these are respectively the bottom, left, top, and right margin sizes. What we need to do is shift the graph up in the plotting window to make room for the data labels on the x-axis...

> par(mar=c(6.4,4.1,2.7,2.1))
> barplot(data.table, beside=T, axis.lty=1, las=2)
> title(main="Passengers by Class:Titanic")
> title(ylab="Number of Passengers")

-----
data(cars)
heatmap.2(as.matrix(cars), cexCol=1, margins=c(5,5))

No comments: