Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R is plotting labels off the page

Tags:

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.

like image 776
K P Avatar asked May 10 '10 23:05

K P


People also ask

How do I turn off axis labels in R?

Data Visualization using R Programming When we create a plot in R, the Y-axis labels are automatically generated and if we want to remove those labels, the plot function can help us. For this purpose, we need to set ylab argument of plot function to blank as ylab="" and yaxt="n" to remove the axis title.

How do you fix an axis in R?

To change the axis scales on a plot in base R Language, we can use the xlim() and ylim() functions. The xlim() and ylim() functions are convenience functions that set the limit of the x-axis and y-axis respectively.

How do you set margins in R?

To visualize how R creates plot margins, look at margin Figure 11.20. You can adjust the size of the margins by specifying a margin parameter using the syntax par(mar = c(bottom, left, top, right)) , where the arguments bottom , left … are the size of the margins. The default value for mar is c(5.1, 4.1, 4.1, 2.1).


1 Answers

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.

like image 149
wkmor1 Avatar answered Oct 23 '22 15:10

wkmor1