Quantcast
Channel: r software hub
Viewing all articles
Browse latest Browse all 1015

Mastering R plot – Part 2: Axis

$
0
0

By Lionel Hertzog

axis1

This is the second part of the Mastering R plot series.

The standard plot function in R allows extensive tuning of every element being plotted. There are, however, many possible ways and the standard help file are hard to grasp at the beginning. In this article we will see how to control every aspects of the axis (labels, tick marks …) in the standard plot function.

Axis title and labels

Create some data and create a plot with default settings.

#some data
x

Here is the plot:

The settings of the plot are usually controlled by the par function (see ?par for the many possible arguments), once the arguments are set in par they apply to all subsequent plots. Some arguments in par (for example cex.axis) can also be set in other plot functions like axis or text. When these arguments are set in these other functions they will then apply only to the current plot. One can then control if he/she wants all plots to be affected by the change or only the current one.

#change the sizes of the axis labels and axis title
op

Here is the plot:
axis2

A handy function to gain deeper control into the axis is the axis function which can control among other things at which values the tick marks are drawn, what axis labels to put under the tick marks, the line type and width of the axis line, the width of the tick marks, the color of the tick marks and axis line.

#we can further control the axis using the axis function
par(op) #re-set the plot to the default settings
plot(x,y,xaxt="n") #this prevent the plotting of x-axis labels
axis(side=1,at=c(5,50,100)) #force the tick marks to be drawn at x=5, 50 and 100
#one can also specify the labels ...read more

Source:: r-bloggers.com


Viewing all articles
Browse latest Browse all 1015

Trending Articles