Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Xlab,Ylab and values of XY-axis color and font size in R plot

Tags:

plot

r

I'd like to change the color and font size of:

  1. Xlab,
  2. Ylab,
  3. values of X and Y-axis
  4. Panel border (color)

in R plot Is there a way to do it?

like image 744
neversaint Avatar asked May 16 '12 04:05

neversaint


People also ask

How do you change the font size of text and axes in R plots?

How to change font size in r? To change the font size of text, use cex (character expansion ratio). The default value is 1. To reduce the text size, use a cex value of less than 1; to increase the text size, use a cex value greater than 1.

How do I change the color of my axis labels in R?

To change the color of X-axis label using ggplot2, we can use theme function that has axis. title. x argument which can be used for changing the color of the label values.

How do I change my axis font in R?

Go to the menu in RStudio and click on Tools and then Global Options. Select the Appearance tab on the left. Again buried in the middle of things is the font size. Change this to 14 or 16 to start with and see what it looks like.

Which function can help customize axes in base graphics of R?

The most basic graphics function in R is the plot function. This function has multiple arguments to configure the final plot: add a title, change axes labels, customize colors, or change line types, among others.


1 Answers

Here's code demonstrating some of the lower level plotting functions that provide the sort of fine-grained control that you're wanting. See the help pages of the several functions for even more options.

plot(rnorm(99), bty="n", axes=FALSE, xlab="", ylab="")
box(col="dodgerblue")
axis(1, col="dodgerblue", col.ticks="green", col.axis="orange", cex.axis=2)
axis(2, col="dodgerblue", col.ticks="green", col.axis="orange", cex.axis=0.8)
mtext("Index", side=1, line=3, col="red", cex=2)
mtext("Value", side=2, line=3, col="purple", cex=0.8)

(The resulting plot is ugly enough that I'll let you run the code yourself, rather than reproduce it here!)

like image 189
Josh O'Brien Avatar answered Oct 02 '22 20:10

Josh O'Brien