# Add an axis to a plot with R software

The goal of this article is to show you how to add axis to a plot using R software. For this end, we’ll use the R axis() function. A simplified format of this function is :

``axis(side, at=NULL, labels=TRUE)``

• side : an integer indicating which side of the plot the axis is to be drawn on; Possible values are :
• 1: below
• 2: left
• 3: above
• 4: right
• at: The points at which tick-marks are to be drawn.
• labels: Texts for tick-mark labels. It can also be logical specifying whether annotations are to be made at the tick-marks.

Example :

``````x<-1:4; y=x*x
# Example 1
plot(x, y, axes = FALSE)
axis(side=1, at = 1:4, labels=LETTERS[1:4])
axis(2)
# Example 2
plot(x, y, axes = FALSE)
axis(side=1, at=1:4, labels=LETTERS[1:4])
axis(2)
box() #- To make it look like "usual" plot``````

Another example is :

``````plot(x, y, pch=18, col="red", type="b",
frame=FALSE, xaxt="n") # Remove x axis
axis(1, 1:4, LETTERS[1:4], col.axis="blue")
axis(3, col = "darkgreen", lty = 2, lwd = 0.5)
axis(4, col = "violet", col.axis = "dark violet", lwd = 2)``````

Note that lty and lwd specify line-type and line-width, respectively.

Infos

This analysis has been performed using R statistical software (ver. 3.1.0).

Enjoyed this article? I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Twitter, Facebook or Linked In.

Show me some love with the like buttons below... Thank you and please don't forget to share and comment below!!
Avez vous aimé cet article? Je vous serais très reconnaissant si vous aidiez à sa diffusion en l'envoyant par courriel à un ami ou en le partageant sur Twitter, Facebook ou Linked In.

Montrez-moi un peu d'amour avec les like ci-dessous ... Merci et n'oubliez pas, s'il vous plaît, de partager et de commenter ci-dessous!

This page has been seen 52149 times