How to change the font size and color of x-axis and y-axis label in a scatterplot with plot function in R?
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)
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')
Which is seriously ugly, but shows part of what you can control
To track down the correct parameters you need to go first to ?plot.default
, which refers you to ?par
and ?axis
:
plot(1, 1 ,xlab="x axis", ylab="y axis", pch=19,
col.lab="red", cex.lab=1.5, # for the xlab and ylab
col="green") # for the points