Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the font size and color of x-axis and y-axis label in a scatterplot with plot function in R?

Tags:

r

scatter-plot

I used the following code to draw a scatterplot. How to increase the font size and change colour of x-axis and y-axis label?

data=read.csv("data.csv")  plot(data$column1,data$column2,xlab="x axis", ylab="y axis",  pch=19) 
like image 373
rebca Avatar asked Sep 20 '12 00:09

rebca


People also ask

How do I change the font size on the X-axis 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.

How do you change the font size on an axis label?

To change the text font for any chart element, such as a title or axis, right–click the element, and then click Font. When the Font box appears make the changes you want.

How do I change the font size in R studio?

Then, you can further adjust the font of code window, console, terminal, environment, and history panels via Tools >> Global Options >> Appearance >> Editor font size.


1 Answers

Look at ?par for the various graphics parameters.

In general cex controls size, col controls colour. If you want to control the colour of a label, the par is col.lab, the colour of the axis annotations col.axis, the colour of the main text, col.main etc. The names are quite intuitive, once you know where to begin.

For example

x <- 1:10 y <- 1:10  plot(x , y,xlab="x axis", ylab="y axis",  pch=19, col.axis = 'blue', col.lab = 'red', cex.axis = 1.5, cex.lab = 2) 

enter image description here

If you need to change the colour / style of the surrounding box and axis lines, then look at ?axis or ?box, and you will find that you will be using the same parameter names within calls to box and axis.

You have a lot of control to make things however you wish.

eg

plot(x , y,xlab="x axis", ylab="y axis",  pch=19,  cex.lab = 2, axes = F,col.lab = 'red') box(col = 'lightblue') axis(1, col = 'blue', col.axis = 'purple', col.ticks = 'darkred', cex.axis = 1.5, font = 2, family = 'serif') axis(2, col = 'maroon', col.axis = 'pink', col.ticks = 'limegreen', cex.axis = 0.9, font =3, family = 'mono') 

enter image description here

Which is seriously ugly, but shows part of what you can control

like image 138
mnel Avatar answered Sep 21 '22 11:09

mnel